Ghi chú phát hành
Học
Lớp công cụ
DataModel
Không Thể Tạo

*Nội dung này được dịch bằng AI (Beta) và có thể có lỗi. Để xem trang này bằng tiếng Anh, hãy nhấp vào đây.


Tóm Tắt
Phương Pháp
BindToClose(function: function):()
GetMessage():string
Đã Lỗi Thời
GetObjects(url: ContentId):Instances
Đã Lỗi Thời
GetRemoteBuildMode():boolean
Đã Lỗi Thời
IsGearTypeAllowed(gearType: Enum.GearType):boolean
Đã Lỗi Thời
SavePlace(saveFilter: Enum.SaveFilter):boolean
Đã Lỗi Thời
SetPlaceId(placeId: number):()
SetUniverseId(universeId: number):()
Gọi Lại
OnClose():Tuple
Đã Lỗi Thời
Thành viên kế thừa
Mẫu mã
LấyDịchVụ()
local Workspace = game:GetService("Workspace")
local Lighting = game:GetService("Lighting")
-- Ví dụ về việc thay đổi thuộc tính của những dịch vụ này
Workspace.Gravity = 20
Lighting.ClockTime = 4

Tài Liệu Tham Khảo API
Thuộc Tính
CreatorId
Chỉ Đọc
Không Sao Chép
Đọc Song Song
DataModel.CreatorId:number
Mẫu mã
Phát hiện khi chủ sở hữu địa điểm tham gia trò chơi
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
if game.CreatorType == Enum.CreatorType.User then
if player.UserId == game.CreatorId then
print("Chủ sở hữu của địa điểm đã tham gia trò chơi!")
end
elseif game.CreatorType == Enum.CreatorType.Group then
if player:IsInGroupAsync(game.CreatorId) then
print("Một thành viên của nhóm sở hữu địa điểm đã tham gia trò chơi!")
end
end
end)

CreatorType
Chỉ Đọc
Không Sao Chép
Đọc Song Song
DataModel.CreatorType:Enum.CreatorType
Mẫu mã
Phát hiện khi chủ sở hữu địa điểm tham gia trò chơi
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
if game.CreatorType == Enum.CreatorType.User then
if player.UserId == game.CreatorId then
print("Chủ sở hữu của địa điểm đã tham gia trò chơi!")
end
elseif game.CreatorType == Enum.CreatorType.Group then
if player:IsInGroupAsync(game.CreatorId) then
print("Một thành viên của nhóm sở hữu địa điểm đã tham gia trò chơi!")
end
end
end)

Environment
Chỉ Đọc
Không Sao Chép
Bảo Mật Kịch Bản Roblox
Đọc Song Song
DataModel.Environment:string

GameId
Chỉ Đọc
Không Sao Chép
Đọc Song Song
DataModel.GameId:number

GearGenreSetting
Đã Lỗi Thời

Genre
Đã Lỗi Thời

JobId
Chỉ Đọc
Không Sao Chép
Đọc Song Song
DataModel.JobId:string

lighting
Đã Lỗi Thời

MatchmakingType
Chỉ Đọc
Không Sao Chép
Đọc Song Song
DataModel.MatchmakingType:Enum.MatchmakingType

PlaceId
Chỉ Đọc
Không Sao Chép
Đọc Song Song
DataModel.PlaceId:number

PlaceVersion
Chỉ Đọc
Không Sao Chép
Đọc Song Song
DataModel.PlaceVersion:number
Mẫu mã
Giao diện số phiên bản máy chủ
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("Phiên bản máy chủ: %s", placeVersion)
textLabel.Parent = versionGui
versionGui.Parent = StarterGui

PrivateServerId
Chỉ Đọc
Không Sao Chép
Đọc Song Song
DataModel.PrivateServerId:string
Mẫu mã
Phát hiện Máy chủ riêng
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
Chỉ Đọc
Không Sao Chép
Đọc Song Song
DataModel.PrivateServerOwnerId:number
Mẫu mã
Phát hiện Máy chủ riêng
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
Chỉ Đọc
Không Sao Chép
Đọc Song Song
DataModel.RunService:RunService

VIPServerId
Đã Lỗi Thời

VIPServerOwnerId
Đã Lỗi Thời

Workspace
Chỉ Đọc
Không Sao Chép
Đọc Song Song
DataModel.Workspace:Workspace

workspace
Đã Lỗi Thời

Phương Pháp
BindToClose
DataModel:BindToClose(function:function):()
Tham Số
function:function
Lợi Nhuận
()
Mẫu mã
Lưu dữ liệu người chơi trước khi tắt máy
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
-- Tránh ghi dữ liệu studio vào sản xuất và làm chậm việc đóng phiên thử nghiệm
return
end
-- Tham chiếu cho việc chờ và tiếp tục sau
local mainThread = coroutine.running()
-- Tăng số đếm cho mỗi luồng mới, giảm xuống khi luồng hoàn thành. Khi đạt 0,
-- luồng riêng biết đó là luồng cuối cùng hoàn thành và nên tiếp tục luồng chính
local numThreadsRunning = 0
-- Gọi hàm này sau sẽ bắt đầu trên một luồng mới vì coroutine.wrap
local startSaveThread = coroutine.wrap(function(userId, sessionData)
-- Thực hiện thao tác lưu
local success, result = pcall(savePlayerDataAsync, userId, sessionData)
if not success then
-- Có thể triển khai lại
warn(string.format("Không thể lưu dữ liệu của %d: %s", userId, result))
end
-- Luồng đã hoàn thành, giảm đếm
numThreadsRunning -= 1
if numThreadsRunning == 0 then
-- Đây là luồng cuối cùng hoàn thành, tiếp tục luồng chính
coroutine.resume(mainThread)
end
end)
-- Giả sử playerData được xóa khỏi bảng dữ liệu trong khi lưu cuối cùng trên PlayerRemoving,
-- nên từ này lặp qua tất cả dữ liệu của người chơi vẫn trong trò chơi chưa được lưu
for userId, sessionData in pairs(allPlayerSessionDataCache) do
numThreadsRunning += 1
-- Vòng lặp này hoàn thành việc chạy và đếm numThreadsRunning trước khi bất kỳ
-- luồng lưu nào bắt đầu vì coroutine.wrap có sự trì hoãn tích hợp khi bắt đầu
startSaveThread(userId, sessionData)
end
if numThreadsRunning > 0 then
-- Dừng tắt máy cho đến khi các luồng lưu hoàn thành. Được tiếp tục bởi luồng lưu cuối khi nó hoàn thành
coroutine.yield()
end
end
game:BindToClose(onServerShutdown)
Liên kết và Xử lý Tắt Game
game:BindToClose(function(closeReason)
print(`Đang đóng với lý do {closeReason}`)
task.wait(3)
print("Xong")
end)

GetJobsInfo
Bảo Mật Plugin
DataModel:GetJobsInfo():{any}
Lợi Nhuận
Mẫu mã
Lấy Thông Tin Công Việc
local jobInfo = game:GetJobsInfo()
local jobTitles = jobInfo[1]
table.remove(jobInfo, 1)
local divider = string.rep("-", 120)
print(divider)
warn("THÔNG TIN CÔNG VIỆC:")
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
Đã Lỗi Thời

GetObjects
Đã Lỗi Thời

GetRemoteBuildMode
Đã Lỗi Thời

IsGearTypeAllowed
Đã Lỗi Thời

IsLoaded
DataModel:IsLoaded():boolean
Lợi Nhuận
Mẫu mã
Màn Hình Tải Tùy Chỉnh
local Players = game:GetService("Players")
local ReplicatedFirst = game:GetService("ReplicatedFirst")
local player = Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
-- Tạo một màn hình tải cơ bản
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 = "Đang Tải"
textLabel.TextSize = 28
textLabel.Parent = screenGui
-- Gán toàn bộ GUI màn hình cho GUI người chơi
screenGui.Parent = playerGui
-- Xóa màn hình tải mặc định
ReplicatedFirst:RemoveDefaultLoadingScreen()
--task.wait(3) -- Tùy chọn để buộc màn hình xuất hiện trong một khoảng thời gian tối thiểu
if not game:IsLoaded() then
game.Loaded:Wait()
end
screenGui:Destroy()

SavePlace
Đã Lỗi Thời

SetPlaceId
Bảo Mật Plugin
DataModel:SetPlaceId(placeId:number):()
Tham Số
placeId:number
Lợi Nhuận
()

SetUniverseId
Bảo Mật Plugin
DataModel:SetUniverseId(universeId:number):()
Tham Số
universeId:number
Lợi Nhuận
()

Sự Kiện
AllowedGearTypeChanged
Đã Lỗi Thời

GraphicsQualityChangeRequest
DataModel.GraphicsQualityChangeRequest(betterQuality:boolean):RBXScriptSignal
Tham Số
betterQuality:boolean
Mẫu mã
Xử lý thay đổi của người dùng về chất lượng đồ họa
game.GraphicsQualityChangeRequest:Connect(function(betterQuality)
if betterQuality then
print("Người dùng đã yêu cầu tăng chất lượng đồ họa!")
else
print("Người dùng đã yêu cầu giảm chất lượng đồ họa!")
end
end)

ItemChanged
Đã Lỗi Thời

Loaded
DataModel.Loaded():RBXScriptSignal

ServerRestartScheduled
Các khả năng: ServerCommunication
DataModel.ServerRestartScheduled(
restartTime:DateTime, source:Enum.CloseReason, attributes:Dictionary
Tham Số
restartTime:DateTime
attributes:Dictionary
Mẫu mã
LịchRestartMáyChủ
local roundInProgress = false -- Được thiết lập ở nơi khác trong mã trò chơi bất cứ khi nào một vòng chơi bắt đầu hoặc kết thúc
local restartPending = false
game.ServerRestartScheduled:Connect(function(restartTime, source, attributes)
local msg = attributes and attributes.message or ""
local timeStr = restartTime:FormatLocalTime("LTS", "en-us") -- vì điều này được thực thi trên máy chủ, nó sẽ ở dạng UTC
-- Chuyển tiếp các trường này tới khách hàng qua remote:FireAllClients() để hiển thị thông điệp tùy chỉnh trong UI của bạn
print(string.format("Máy chủ khởi động lại vào lúc %s từ nguồn: %s. Lý do: %s.", timeStr, tostring(source), msg))
if not roundInProgress then
print("Không có vòng chơi nào đang diễn ra. Đang dịch chuyển người chơi trong 10 giây")
task.wait(10)
-- Dịch chuyển người chơi khi một lần khởi động lại đã được lên lịch sẽ đưa họ đến một máy chủ trên phiên bản địa điểm mới nhất
game:GetService("TeleportService"):TeleportAsync(game.PlaceId, game:GetService("Players"):GetPlayers())
else
-- Bạn có thể thêm mã để dịch chuyển người chơi sau khi một vòng chơi kết thúc nếu restartPending là true.
restartPending = true
end
end)

Gọi Lại
OnClose
Đã Lỗi Thời

©2026 Roblox Corporation. Roblox, logo Roblox và Powering Imagination là các nhãn hiệu đã đăng ký và chưa đăng ký của chúng tôi tại Hoa Kỳ và các quốc gia khác.