데이터 모델(일반적으로 액세스하는 전역 변수 이후에 알려진 데이터 모델)은 Roblox의 부모-자식 계층의 루트입니다.직접 자식은 Roblox 게임의 기본 구성 요소로 작용하는 서비스, 예를 들어 Workspace 및 Lighting ,입니다.
코드 샘플
Demonstrates using game, the root instance of DataModel, to get services such as Workspace and Lighting.
local Workspace = game:GetService("Workspace")
local Lighting = game:GetService("Lighting")
-- Examples of modifying properties of these services
Workspace.Gravity = 20
Lighting.ClockTime = 4
요약
속성
플레이스소유하는 사용자 또는 그룹의 ID를 설명합니다.
플레이스Enum.CreatorType를 설명하며, 장소가 사용자 또는 그룹에 소유되었는지 여부를 설명합니다.
서버에서 실행 중인 장소가 속한 경험의 ID를 설명합니다.
기능적이지 않음. 역사적으로 장소의 Enum.Genre를 Roblox 웹사이트에 설정된 것으로 묘사했습니다.
실행 중인 게임 서버 인스턴스의 고유 식별자.
서버의 플레이어가 매치메이킹으로 처리되는 방식을 나타냅니다.
서버에서 실행 중인 장소의 ID를 설명합니다.
서버가 실행 중인 장소의 버전을 설명합니다.
서버가 개인 서버인 경우 서버의 개인 서버 ID 또는 reserved server 를 설명합니다.
서버가 비공개인 경우 비공개 서버를 소유하는 의 설명입니다.
Workspace 서비스에 대한 참조.
메서드
서버가 종료되기 전에 호출할 함수를 바인딩합니다.
태스크 스케줄러에서 수행한 작업에 대한 기본 정보가 포함된 테이블을 반환합니다.
지정된 콘텐츠 URL과 연결된 배열 Instances를 반환합니다.
클라이언트가 처음으로 게임을 로드하는 것을 완료했는지 여부에 따라 반환합니다. true를 반환합니다.
현재 게임 인스턴스의 DataModel.PlaceId를 지정된 placeId로 설정합니다.
현재 게임 인스턴스의 DataModel.GameId를 지정된 universId로 설정합니다.
메서드
지정된 className에 의해 이미 생성된 경우 지정된 서비스를 반환하고 유효하지 않은 이름에 대한 오류를 발생시킵니다.
요청한 클래스 이름으로 서비스를 반환하고, 존재하지 않으면 생성합니다.
이벤트
사용자가 프롬프트할 때 발생하며 핫키를 사용하여 그래픽 품질을 높이거나 낮춥니다.
게임이 처음으로 로드되는 동안 클라이언트에서 발생하는 화재.
이벤트
현재 장소가 종료될 때 발화합니다.
서비스가 생성될 때 해고됩니다.
서비스가 제거될 때 발사됩니다.
속성
CreatorId
코드 샘플
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
if game.CreatorType == Enum.CreatorType.User then
if player.UserId == game.CreatorId then
print("The place owner has joined the game!")
end
elseif game.CreatorType == Enum.CreatorType.Group then
if player:IsInGroup(game.CreatorId) then
print("A member of the group that owns the place has joined the game!")
end
end
end)
CreatorType
코드 샘플
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
if game.CreatorType == Enum.CreatorType.User then
if player.UserId == game.CreatorId then
print("The place owner has joined the game!")
end
elseif game.CreatorType == Enum.CreatorType.Group then
if player:IsInGroup(game.CreatorId) then
print("A member of the group that owns the place has joined the game!")
end
end
end)
Environment
GameId
JobId
MatchmakingType
PlaceId
PlaceVersion
코드 샘플
local StarterGui = game:GetService("StarterGui")
local versionGui = Instance.new("ScreenGui")
local textLabel = Instance.new("TextLabel")
textLabel.Position = UDim2.new(1, -10, 1, 0)
textLabel.AnchorPoint = Vector2.new(1, 1)
textLabel.Size = UDim2.new(0, 150, 0, 40)
textLabel.BackgroundTransparency = 1
textLabel.TextColor3 = Color3.new(1, 1, 1)
textLabel.TextStrokeTransparency = 0
textLabel.TextXAlignment = Enum.TextXAlignment.Right
textLabel.TextScaled = true
local placeVersion = game.PlaceVersion
textLabel.Text = string.format("Server version: %s", placeVersion)
textLabel.Parent = versionGui
versionGui.Parent = StarterGui
PrivateServerId
코드 샘플
local function getServerType()
if game.PrivateServerId ~= "" then
if game.PrivateServerOwnerId ~= 0 then
return "VIPServer"
else
return "ReservedServer"
end
else
return "StandardServer"
end
end
print(getServerType())
PrivateServerOwnerId
코드 샘플
local function getServerType()
if game.PrivateServerId ~= "" then
if game.PrivateServerOwnerId ~= 0 then
return "VIPServer"
else
return "ReservedServer"
end
else
return "StandardServer"
end
end
print(getServerType())
Workspace
메서드
BindToClose
매개 변수
반환
코드 샘플
local DataStoreService = game:GetService("DataStoreService")
local RunService = game:GetService("RunService")
local playerDataStore = DataStoreService:GetDataStore("PlayerData")
local allPlayerSessionDataCache = {}
local function savePlayerDataAsync(userId, data)
return playerDataStore:UpdateAsync(userId, function(oldData)
return data
end)
end
local function onServerShutdown(closeReason)
if RunService:IsStudio() then
-- Avoid writing studio data to production and stalling test session closing
return
end
-- Reference for yielding and resuming later
local mainThread = coroutine.running()
-- Counts up for each new thread, down when the thread finishes. When 0 is reached,
-- the individual thread knows it's the last thread to finish and should resume the main thread
local numThreadsRunning = 0
-- Calling this function later starts on a new thread because of coroutine.wrap
local startSaveThread = coroutine.wrap(function(userId, sessionData)
-- Perform the save operation
local success, result = pcall(savePlayerDataAsync, userId, sessionData)
if not success then
-- Could implement a retry
warn(string.format("Failed to save %d's data: %s", userId, result))
end
-- Thread finished, decrement counter
numThreadsRunning -= 1
if numThreadsRunning == 0 then
-- This was the last thread to finish, resume main thread
coroutine.resume(mainThread)
end
end)
-- This assumes playerData gets cleared from the data table during a final save on PlayerRemoving,
-- so this is iterating over all the data of players still in the game that hasn't been saved
for userId, sessionData in pairs(allPlayerSessionDataCache) do
numThreadsRunning += 1
-- This loop finishes running and counting numThreadsRunning before any of
-- the save threads start because coroutine.wrap has built-in deferral on start
startSaveThread(userId, sessionData)
end
if numThreadsRunning > 0 then
-- Stall shutdown until save threads finish. Resumed by the last save thread when it finishes
coroutine.yield()
end
end
game:BindToClose(onServerShutdown)
game:BindToClose(function(closeReason)
print(`Closing with reason {closeReason}`)
task.wait(3)
print("Done")
end)
GetJobsInfo
반환
코드 샘플
local jobInfo = game:GetJobsInfo()
local jobTitles = jobInfo[1]
table.remove(jobInfo, 1)
local divider = string.rep("-", 120)
print(divider)
warn("JOB INFO:")
print(divider)
for _, job in pairs(jobInfo) do
for jobIndex, jobValue in pairs(job) do
local jobTitle = jobTitles[jobIndex]
warn(jobTitle, "=", jobValue)
end
print(divider)
end
GetObjects
매개 변수
반환
코드 샘플
local Selection = game:GetService("Selection")
local WEB_URL = "plugin URL here"
local function downloadPlugin(webURL)
-- get the content URL
local contentID = string.match(webURL, "%d+")
local contentURL = "rbxassetid://" .. contentID
-- download the objects
local objects = game:GetObjects(contentURL)
-- decide where to parent them
local selection = Selection:Get()
local parent = #selection == 1 and selection[1] or workspace
-- parent the objects
for _, object in pairs(objects) do
object.Parent = parent
end
end
downloadPlugin(WEB_URL)
local IMAGES = {
-- 여기에 배열에 데칼 웹 URL을 삽입(문자열로)
}
-- 사전 열기
local outputString = "textures = {"
-- 사전에 새 항목을 추가하는 유틸리티 함수(문자열로)
local function addEntryToDictionary(original, new)
outputString = outputString
.. "\n" -- 새 줄
.. " " -- 인디언트
.. '["'
.. original
.. '"]' -- 키
.. ' = "'
.. new
.. '",' -- 값
end
print("Starting conversion")
for _, webURL in pairs(IMAGES) do
-- 콘텐츠 URL 가져오기
local contentID = string.match(webURL, "%d+")
local contentURL = "rbxassetid://" .. contentID
local success, result = pcall(function()
local objects = game:GetObjects(contentURL)
return objects[1].Texture
end)
if success then
addEntryToDictionary(webURL, result)
else
addEntryToDictionary(webURL, "Error downloading decal")
end
task.wait()
end
print("Conversion complete")
-- 사전 닫기
outputString = outputString .. "\n}"
-- 사전 출력
print(outputString)
IsLoaded
반환
코드 샘플
local Players = game:GetService("Players")
local ReplicatedFirst = game:GetService("ReplicatedFirst")
local player = Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
-- 기본 로딩 화면 생성
local screenGui = Instance.new("ScreenGui")
screenGui.IgnoreGuiInset = true
local textLabel = Instance.new("TextLabel")
textLabel.Size = UDim2.new(1, 0, 1, 0)
textLabel.BackgroundColor3 = Color3.fromRGB(0, 20, 40)
textLabel.Font = Enum.Font.GothamMedium
textLabel.TextColor3 = Color3.new(0.8, 0.8, 0.8)
textLabel.Text = "Loading"
textLabel.TextSize = 28
textLabel.Parent = screenGui
-- 플레이어 GUI에 전체 화면 GUI 부모 지정
screenGui.Parent = playerGui
-- 기본 로딩 화면 제거
ReplicatedFirst:RemoveDefaultLoadingScreen()
--wait(3) -- 선택적으로 최소 시간 동안 화면 표시 강제
if not game:IsLoaded() then
game.Loaded:Wait()
end
screenGui:Destroy()
이벤트
GraphicsQualityChangeRequest
매개 변수
코드 샘플
game.GraphicsQualityChangeRequest:Connect(function(betterQuality)
if betterQuality then
print("The user has requested an increase in graphics quality!")
else
print("The user has requested a decrease in graphics quality!")
end
end)