เรียนรู้
Engine Class
DataModel
ไม่สามารถสร้าง

*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่


สรุป
คุณสมบัติ
GearGenreSetting:Enum.GearGenreSetting
เลิกใช้แล้ว
Genre:Enum.Genre
เลิกใช้แล้ว
lighting:Instance
เลิกใช้แล้ว
VIPServerId:string
เลิกใช้แล้ว
VIPServerOwnerId:number
เลิกใช้แล้ว
workspace:Workspace
เลิกใช้แล้ว
วิธีการ
BindToClose(function: function):()
GetMessage():string
เลิกใช้แล้ว
GetObjects(url: ContentId):Instances
เลิกใช้แล้ว
GetRemoteBuildMode():boolean
เลิกใช้แล้ว
IsGearTypeAllowed(gearType: Enum.GearType):boolean
เลิกใช้แล้ว
SavePlace(saveFilter: Enum.SaveFilter):boolean
เลิกใช้แล้ว
SetPlaceId(placeId: number):()
SetUniverseId(universeId: number):()
เหตุการณ์
AllowedGearTypeChanged():RBXScriptSignal
เลิกใช้แล้ว
ItemChanged(object: Instance,descriptor: string):RBXScriptSignal
เลิกใช้แล้ว
Callbacks
OnClose():Tuple
เลิกใช้แล้ว
สมาชิกที่ได้รับทอด
ตัวอย่างโค้ด
GetService()
local Workspace = game:GetService("Workspace")
local Lighting = game:GetService("Lighting")
-- ตัวอย่างการปรับคุณสมบัติของบริการนี้
Workspace.Gravity = 20
Lighting.ClockTime = 4

เอกสารอ้างอิงเกี่ยวกับ API
คุณสมบัติ
CreatorId
อ่านอย่างเดียว
ไม่ซ้ำ
อ่านพร้อมๆ กัน
DataModel.CreatorId:number
ตัวอย่างโค้ด
ตรวจจับเมื่อเจ้าของสถานที่เข้าร่วมเกม
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
อ่านอย่างเดียว
ไม่ซ้ำ
อ่านพร้อมๆ กัน
DataModel.CreatorType:Enum.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)

Environment
อ่านอย่างเดียว
ไม่ซ้ำ
การรักษาความปลอดภัยของสคริปต์ Roblox
อ่านพร้อมๆ กัน
DataModel.Environment:string

GameId
อ่านอย่างเดียว
ไม่ซ้ำ
อ่านพร้อมๆ กัน
DataModel.GameId:number

GearGenreSetting
เลิกใช้แล้ว

Genre
เลิกใช้แล้ว

JobId
อ่านอย่างเดียว
ไม่ซ้ำ
อ่านพร้อมๆ กัน
DataModel.JobId:string

lighting
เลิกใช้แล้ว

MatchmakingType
อ่านอย่างเดียว
ไม่ซ้ำ
อ่านพร้อมๆ กัน
DataModel.MatchmakingType:Enum.MatchmakingType

PlaceId
อ่านอย่างเดียว
ไม่ซ้ำ
อ่านพร้อมๆ กัน
DataModel.PlaceId:number

PlaceVersion
อ่านอย่างเดียว
ไม่ซ้ำ
อ่านพร้อมๆ กัน
DataModel.PlaceVersion:number
ตัวอย่างโค้ด
หมายเลขเวอร์ชันของเซิร์ฟเวอร์ 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 = StarterGui

PrivateServerId
อ่านอย่างเดียว
ไม่ซ้ำ
อ่านพร้อมๆ กัน
DataModel.PrivateServerId:string
ตัวอย่างโค้ด
การตรวจจับเซิร์ฟเวอร์ส่วนตัว
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
อ่านอย่างเดียว
ไม่ซ้ำ
อ่านพร้อมๆ กัน
DataModel.PrivateServerOwnerId:number
ตัวอย่างโค้ด
การตรวจจับเซิร์ฟเวอร์ส่วนตัว
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())

RunService
อ่านอย่างเดียว
ไม่ซ้ำ
อ่านพร้อมๆ กัน
DataModel.RunService:RunService

VIPServerId
เลิกใช้แล้ว

VIPServerOwnerId
เลิกใช้แล้ว

Workspace
อ่านอย่างเดียว
ไม่ซ้ำ
อ่านพร้อมๆ กัน
DataModel.Workspace:Workspace

workspace
เลิกใช้แล้ว

วิธีการ
BindToClose
DataModel:BindToClose(function:function):()
พารามิเตอร์
function:function
ส่งค่ากลับ
()
ตัวอย่างโค้ด
บันทึกข้อมูลผู้เล่นก่อนที่จะปิด
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,
-- ดังนั้นนี่คือการวนซ้ำผ่านข้อมูลทั้งหมดของผู้เล่นที่ยังอยู่ในเกมที่ยังไม่ได้ถูกบันทึก
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(`Closing with reason {closeReason}`)
task.wait(3)
print("เสร็จสิ้น")
end)

GetJobsInfo
การรักษาความปลอดภัยของปลั๊กอิน
DataModel:GetJobsInfo():{any}
ส่งค่ากลับ
ตัวอย่างโค้ด
การได้รับข้อมูลงาน
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)
end

GetMessage
เลิกใช้แล้ว

GetObjects
เลิกใช้แล้ว

GetRemoteBuildMode
เลิกใช้แล้ว

IsGearTypeAllowed
เลิกใช้แล้ว

IsLoaded
DataModel:IsLoaded():boolean
ส่งค่ากลับ
ตัวอย่างโค้ด
หน้าจอโหลดที่กำหนดเอง
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
เลิกใช้แล้ว

SetPlaceId
การรักษาความปลอดภัยของปลั๊กอิน
DataModel:SetPlaceId(placeId:number):()
พารามิเตอร์
placeId:number
ส่งค่ากลับ
()

SetUniverseId
การรักษาความปลอดภัยของปลั๊กอิน
DataModel:SetUniverseId(universeId:number):()
พารามิเตอร์
universeId:number
ส่งค่ากลับ
()

เหตุการณ์
AllowedGearTypeChanged
เลิกใช้แล้ว

GraphicsQualityChangeRequest
DataModel.GraphicsQualityChangeRequest(betterQuality:boolean):RBXScriptSignal
พารามิเตอร์
betterQuality:boolean
ตัวอย่างโค้ด
การจัดการการเปลี่ยนแปลงของผู้ใช้ในคุณภาพกราฟิก
game.GraphicsQualityChangeRequest:Connect(function(betterQuality)
if betterQuality then
print("ผู้ใช้ได้ขอเพิ่มคุณภาพกราฟิก!")
else
print("ผู้ใช้ได้ขอให้ลดคุณภาพกราฟิก!")
end
end)

ItemChanged
เลิกใช้แล้ว

Loaded
DataModel.Loaded():RBXScriptSignal

ServerRestartScheduled
ความสามารถ: ServerCommunication
DataModel.ServerRestartScheduled(
restartTime:DateTime, source:Enum.CloseReason, attributes:Dictionary
พารามิเตอร์
restartTime:DateTime
attributes:Dictionary
ตัวอย่างโค้ด
กำหนดการรีเซิร์ฟเวอร์
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
-- ส่งข้อมูลเหล่านี้ไปยังคลไอพีผ่าน remote:FireAllClients() เพื่อแสดงข้อความที่ปรับแต่งใน UI ของคุณ
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 เป็นจริง
restartPending = true
end
end)

Callbacks
OnClose
เลิกใช้แล้ว

©2026 Roblox Corporation. Roblox, โลโก้ Roblox และ Powering Imagination เป็นส่วนหนึ่งของเครื่องหมายการค้าที่จดทะเบียน และไม่ได้จดทะเบียนของเราในสหรัฐฯ และประเทศอื่นๆ