요약
속성
메서드
BindToClose(function: function):() |
GetObjects(url: ContentId):Instances |
IsGearTypeAllowed(gearType: Enum.GearType):boolean |
SavePlace(saveFilter: Enum.SaveFilter):boolean |
SetPlaceId(placeId: number):() |
SetUniverseId(universeId: number):() |
이벤트
GraphicsQualityChangeRequest(betterQuality: boolean):RBXScriptSignal |
ItemChanged(object: Instance,descriptor: string):RBXScriptSignal |
ServerRestartScheduled(restartTime: DateTime,source: Enum.CloseReason,attributes: Dictionary):RBXScriptSignal |
상속된 멤버
코드 샘플
GetService()
local Workspace = game:GetService("Workspace")
local Lighting = game:GetService("Lighting")
-- 이 서비스의 속성을 수정하는 예제
Workspace.Gravity = 20
Lighting.ClockTime = 4API 참조
속성
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("장소 소유자가 게임에 참여했습니다!")
end
elseif game.CreatorType == Enum.CreatorType.Group then
if player:IsInGroupAsync(game.CreatorId) then
print("장소를 소유한 그룹의 구성원이 게임에 참여했습니다!")
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("장소 소유자가 게임에 참여했습니다!")
end
elseif game.CreatorType == Enum.CreatorType.Group then
if player:IsInGroupAsync(game.CreatorId) then
print("장소를 소유한 그룹의 구성원이 게임에 참여했습니다!")
end
end
end)GearGenreSetting
Genre
lighting
PlaceVersion
코드 샘플
서버 버전 번호 GUI
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("서버 버전: %s", placeVersion)
textLabel.Parent = versionGui
versionGui.Parent = StarterGuiPrivateServerId
코드 샘플
개인 서버 감지
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())VIPServerId
VIPServerOwnerId
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
-- 스튜디오 데이터가 프로덕션에 기록되는 것을 방지하고 시험 세션 종료를 지연시킴
return
end
-- 나중에 일시 중지하고 다시 시작하기 위한 참조
local mainThread = coroutine.running()
-- 새 스레드에 대해 카운트 업하고, 스레드가 끝나면 다운합니다. 0이 되면,
-- 개별 스레드는 마지막 스레드임을 알고 메인 스레드를 재개해야 합니다.
local numThreadsRunning = 0
-- 이 함수를 나중에 호출하면 coroutine.wrap으로 새 스레드에서 시작합니다.
local startSaveThread = coroutine.wrap(function(userId, sessionData)
-- 저장 작업 수행
local success, result = pcall(savePlayerDataAsync, userId, sessionData)
if not success then
-- 재시도를 구현할 수 있습니다.
warn(string.format("%d의 데이터를 저장하지 못했습니다: %s", userId, result))
end
-- 스레드가 끝났으므로 카운터 감소
numThreadsRunning -= 1
if numThreadsRunning == 0 then
-- 이것이 마지막으로 끝난 스레드였으므로 메인 스레드를 재개합니다.
coroutine.resume(mainThread)
end
end)
-- 이것은 PlayerRemoving 동안 마지막 저장 시 playerData가 데이터 테이블에서 지워진다고 가정합니다.
-- 따라서 저장되지 않은 게임에 여전히 있는 플레이어의 모든 데이터를 반복합니다.
for userId, sessionData in pairs(allPlayerSessionDataCache) do
numThreadsRunning += 1
-- 이 루프는 스레드가 시작되기 전에 numThreadsRunning의 실행과 카운팅을 마칩니다.
-- coroutine.wrap이 시작 시 자동으로 지연됩니다.
startSaveThread(userId, sessionData)
end
if numThreadsRunning > 0 then
-- 저장 스레드가 끝날 때까지 종료를 지연합니다. 마지막 저장 스레드가 끝날 때 재개됩니다.
coroutine.yield()
end
end
game:BindToClose(onServerShutdown)게임 종료에 대한 바인딩 및 처리
game:BindToClose(function(closeReason)
print(`종료 사유로 닫힘 {closeReason}`)
task.wait(3)
print("완료")
end)GetJobsInfo
반환
코드 샘플
직업 정보 가져오기
local jobInfo = game:GetJobsInfo()
local jobTitles = jobInfo[1]
table.remove(jobInfo, 1)
local divider = string.rep("-", 120)
print(divider)
warn("직업 정보:")
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)
endGetMessage
GetObjects
GetRemoteBuildMode
IsGearTypeAllowed
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 = "로딩 중"
textLabel.TextSize = 28
textLabel.Parent = screenGui
-- 전체 화면 GUI를 플레이어 GUI에 부모로 설정
screenGui.Parent = playerGui
-- 기본 로딩 화면 제거
ReplicatedFirst:RemoveDefaultLoadingScreen()
--task.wait(3) -- 옵션으로 화면이 최소 몇 초 동안 표시되도록 강제 설정
if not game:IsLoaded() then
game.Loaded:Wait()
end
screenGui:Destroy()SavePlace
이벤트
AllowedGearTypeChanged
GraphicsQualityChangeRequest
매개 변수
코드 샘플
그래픽 품질에서 사용자 변경 처리
game.GraphicsQualityChangeRequest:Connect(function(betterQuality)
if betterQuality then
print("사용자가 그래픽 품질을 높이도록 요청했습니다!")
else
print("사용자가 그래픽 품질을 낮추도록 요청했습니다!")
end
end)ItemChanged
ServerRestartScheduled
DataModel.ServerRestartScheduled(
매개 변수
코드 샘플
서버재시작예정
local roundInProgress = false -- 게임 코드에서 게임 라운드가 시작되거나 끝날 때 설정됩니다.
local restartPending = false
game.ServerRestartScheduled:Connect(function(restartTime, source, attributes)
local msg = attributes and attributes.message or ""
local timeStr = restartTime:FormatLocalTime("LTS", "en-us") -- 서버에서 실행되므로 UTC로 표시됩니다.
-- 클라이언트에 사용자 정의 메시지를 UI에 표시하기 위해 remote:FireAllClients()를 통해 이 필드를 전달합니다.
print(string.format("서버 재시작은 %s로부터입니다: %s. 이유: %s.", timeStr, tostring(source), msg))
if not roundInProgress then
print("진행 중인 라운드가 없습니다. 10초 후에 플레이어를 텔레포트합니다.")
task.wait(10)
-- 재시작이 예정된 경우 플레이어를 텔레포트하면 최신 장소 버전의 서버로 이동됩니다.
game:GetService("TeleportService"):TeleportAsync(game.PlaceId, game:GetService("Players"):GetPlayers())
else
-- restartPending가 true일 경우 게임 라운드가 끝난 후 플레이어를 텔레포트하는 코드를 추가할 수 있습니다.
restartPending = true
end
end)콜백
OnClose