DataModel
*このコンテンツは、ベータ版のAI(人工知能)を使用して翻訳されており、エラーが含まれている可能性があります。このページを英語で表示するには、 こちら をクリックしてください。
データモデル (一般的にそれにアクセスするグローバル変数の後ろにある として知られている) は、Roblox の親子階層の根です。その直接の子供は、Workspace や Lighting など、Roblox ゲームの基本コンポーネントとして機能するサービスです。
コードサンプル
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 を説明します。
サーバーが実行されている場所のバージョンを説明します。
サーバーがプライベートサーバーか reserved server である場合、サーバーのプライベートサーバー IDを説明します。
サーバーがプライベートである場合、プライベートサーバーを所有する を説明します。
Workspace サービスへの参照。
方法
サーバーがシャットダウンする前に呼び出される関数をバインドします。
タスクスケジューラによって実行されたジョブに関する基本情報を含むテーブルを返します。
返すのは、Instances に関連付けられた配列で、指定されたコンテンツ URLに対応します。
クライアントがゲームを初めてロードしたのが終わった場合は、真を返します。
現在のゲームインスタンスの DataModel.PlaceId を指定された placeId に設定します。
現在のゲームインスタンスの DataModel.GameId を指定された universeId に設定します。
指定された className によって指定されたサービスを返す、既に作成されている場合は無効な名前のエラー。
リクエストされたクラス名でサービスを返し、存在しない場合は作成します。
イベント
ユーザーがプロンプトを表示し、ホットキーを使用してグラフィック品質を増加または減少させるときに発火します。
ゲームが初めてロードされるときに、クライアントで発火します。
現在の場所が終了すると発火します。
サービスが作成されたときに発射されます。
サービスが削除されるときに発射されます。
プロパティ
CreatorId
このプロパティは、場プレースを所有するユーザーまたはグループの ID を説明します。DataModel.CreatorType プロパティが 'ユーザー' である場合、CreatorId は場プレースの所有者の Player.UserId になります。If the DataModel.CreatorType が 'グループ' である場合、CreatorId は場プレースを所有するグループの ID になります。
コードサンプル
This code sample will print an output when the user that owns the game, or a member of the group that owns the game joins the server.
To run this script, place it inside a Script in ServerScriptService
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
このプロパティは、場所がユーザーまたはグループに所有されているかどうかにかかわらず、場プレースの Enum.CreatorType を説明します。
If the Enum.CreatorType is 'User' , then the DataModel.CreatorId プロパティは、ゲームを所有するアカウントの UserId を説明します。CreatorType が 'グループ' である場合、グループ ID を説明します。
コードサンプル
This code sample will print an output when the user that owns the game, or a member of the group that owns the game joins the server.
To run this script, place it inside a Script in ServerScriptService
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
このプロパティは、サーバー上で実行されている場所が属するエクスペリエンスの IDを説明します。
参照してください: See Also
- DataModel.PlaceId , サーバー上で実行されている場所のIDを説明する
- DataModel.JobId , 実行中のサーバーゲームインスタンスのユニークな識別子
- TeleportService , これはゲーム間で Players を輸送するために使用できるサービス
Genre
このプロパティは壊れており、使用してはならない。
このプロパティは、歴史的に Roblox ウェブサイトに設定された場所の Enum.Genre を記述しました。
このプロパティ、および DataModel.GearGenreSetting 、は、Roblox ウェブサイトに存在するジャンルが Enum.Genre 枚列に反映されていないため、これ以上正しく機能しません。結果として、このプロパティを読む試みがエラーを発生させる可能性があります。
JobId
このプロパティは、実行中のゲームサーバーインスタンスのユニークな識別子です。それは世界的に唯一の識別子 (UUID) であり、過去の 2つのサーバーまたは現在の 2つのサーバーが同じIDを持つことは決してありません。
Studio で空の文字列にデフォルトします。
参照してください: See Also
- TeleportService:GetPlayerPlaceInstanceAsync() は、ユーザーの現在のサーバーの DataModel.JobId を取得するのに使用できます。
- TeleportService:TeleportToPlaceInstance() は、特定のサーバーに Player をテレポートするのに使用できます。
- DataModel.PrivateServerId ゲームサーバーインスタンスが属するプライベートサーバーの ID を説明します。
- HttpService:GenerateGUID() , 自分の独自の UUID を生成するために使用できる機能。
MatchmakingType
このプロパティは、サーバー上のプレイヤーがマッチメイキングで処理される方法を表します。異なる MatchmakingTypes を持つプレイヤーは、同じサーバーに入るか、テレポートすることはできません。
このプロパティは、サーバー DataModel でのみ有効であり、すべてのクライアントの値として Enum.MatchmakingType.Default であるため、サーバー側の Script 内でのみこのプロパティを参照します。
PlaceId
このプロパティは、サーバー上で実行されている場所の ID を説明します。
場所が Roblox に公開されていない場合、この ID は使用されているテンプレートと一致します。
参照してください: See Also
- DataModel.GameId , 現在の場所が属するエクスペリエンスのIDを説明する
- DataModel.JobId , 実行中のサーバーゲームインスタンスのユニークな識別子
- TeleportService , これは場所間で Players を輸送するために使用できるサービス
PlaceVersion
このプロパティは、サーバーが実行されている場所のバージョンを説明します。
このバージョン番号は、プレース所の設定の バージョン履歴 セクションに表示されたバージョン番号と一致します。Roblox クライアントの現在のバージョンではありません。このプロパティは、公開されていないすべてのエクスペリエンスの 0です。
プレース用のサーバーインスタンスが作成されると、プレースの現在のバージョンを使用します。このサーバーが実行されている間、場所が後で更新された場合、サーバーは現在のバージョンで残ります。
このプロパティは、デバッグを助けるために、現在のゲームバージョンを ScreenGui 表示するために使用できます Players 。
コードサンプル
This code sample will place a simple GUI in the StarterGui showing the place version the server is running at.
To use this sample, place it inside a Script in ServerScriptService.
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
このプロパティは、サーバーがプライベートサーバーの場合、サーバーのプライベートサーバー IDを説明します。
サーバーがプライベートサーバーでない場合、この属性は空の文字列になります。
プライベートサーバー
プライベートサーバーはフォロー中を参照します:
- 予約済みサーバー、開発者が TeleportService:ReserveServer() を使用して作成したプライベートサーバー
PrivateServerId vs ジョブID
サーバーの PrivateServerId は DataModel.JobId と異なります。JobId は現在のサーバーインスタンスの唯一の識別子です。
プライベートサーバー (プライベートまたは予約サーバー) は、時間経過とともに複数のサーバーインスタンスを関連付けることができます。これは、プライベトサーバーでは 1つのサーバーインスタンスしか同時に実行できないものの、新しいサーバーインスタンスはプレイヤーがゲームに参加して退出すると開き、閉じることができるためです。たとえば、サーバーに誰もプレイしていないときにサーバーインスタンスが実行されていません。プライベートサーバーID は、これらすべてのサーバーインスタンスで一貫し、DataModel.JobId はそれぞれ異なります。
参照してください:
- DataModel.PrivateServerOwnerId , プライベートサーバーの所有者を説明するプロパティ
- TeleportService:ReserveServer() , 予約されたサーバーを作成する機能
コードサンプル
DataModel.PrivateServerId and DataModel.PrivateServerOwnerId can be used to detect if the current server instance is a standard server, a VIP server or a reserved server.
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
このプロパティは、サーバーがプライベートの場合、UserId が所有する Player の プライベートサーバー を説明します。
サーバーが標準または予約サーバーである場合、このプロパティは 0 に設定されます。
このプロパティは、例えば、プライベートサーバーのオーナーが Player であるかどうかを識別するのに使用できます:
local Players = game:GetService("Players")
-- これはプライベートサーバーですか?
if game.PrivateServerId ~= "" and game.PrivateServerOwnerId ~= 0 then
-- 新しいプレイヤーが追加されるのを聞く
Players.PlayerAdded:Connect(function(player)
-- プレイヤーがサーバーのオーナーかどうかをチェック
if player.UserId == game.PrivateServerOwnerId then
print("The private server owner has joined the game")
end
end)
end
参照してください:
- DataModel.PrivateServerId , プライベートのユニークIDを説明するプロパティと reserved servers
コードサンプル
DataModel.PrivateServerId and DataModel.PrivateServerOwnerId can be used to detect if the current server instance is a standard server, a VIP server or a reserved server.
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())
方法
BindToClose
サーバーがシャットダウンする前に呼び出される関数をバインドします。バインド関数がパラメータを受け入れる場合、Enum.CloseReason サーバーシャットダウンの理由を指定するパラメータを渡します。
BindToClose() を複数回呼び出して、複数の機能をバインドできます。バインドされた機能は並行して呼び出され、同時に実行されます。
エクスペリエンスサーバーは、シャットダウンする前にすべてのバインドされた機能が実行を停止するのを 30 秒待ちます。30秒後、機能がまだ実行中であっても、サーバーはシャットダウンします。
現在のセッションが Roblox Studio にないことを確認するには、RunService:IsStudio() を使用します。これにより、バインド機能がオフラインテストセッションで実行を完了できなくなります。
DataStoreService を使用するときは、すべての保存されていないデータを BindToClose にバインドするために DataStores を使用する必要もあります。これにより、サーバーが予期せずシャットダウンした場合のデータ損失を防げます。
参照してください:
- Enum.CloseReason エクスペリエンスサーバーのシャットダウンの理由。
- PluginGui:BindToClose() , は機能を PluginGui 閉じるボタンにバインドします。
パラメータ
エクスペリエンスサーバーがシャットダウンする前に呼び出される機能。バインド関数がパラメータを受け入れる場合、Enum.CloseReason サーバーシャットダウンの理由を指定するパラメータを渡します。
戻り値
コードサンプル
The following code sample is an example of how DataModel:BindToClose() can be used to save player data in the event of a server shutdown. In this example, player data is stored in a dictionary named playerData with UserIds as keys.
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)
The following example prints the close reason to the output. It prints Done after three seconds, and then allows Roblox to shut down the experience server.
The close reason matches one of the values in Enum.CloseReason.
game:BindToClose(function(closeReason)
print(`Closing with reason {closeReason}`)
task.wait(3)
print("Done")
end)
GetJobsInfo
タスクスケジューラによって実行されたジョブに関する基本情報を含むテーブルを返します。
計算では、タスクスケジューラは、適切な間隔でキータスクを実行する責任のあるシステムです。
Roblox Studio のタスクスケジューラーウィンドウでも、ライブタスクスケジューラー統計を見つけることができます。
テーブルに返された最初のエントリは、利用可能な統計 (またはヘッドライン) を含む参照辞書です。次の形式です:
{["name"] = "name",["averageDutyCycle"] = "averageDutyCycle",["averageStepsPerSecond"] = "averageStepsPerSecond",["averageStepTime"] = "averageStepTime",["averageError"] = "averageError",["isRunning"] = "isRunning",}
返されたテーブルの後続のエントリは、タスクスケジューラによって実行されたジョブの上記の統計を含む辞書です。たとえば:
{["name"] = "Heartbeat",["averageDutyCycle"] = 0,["averageStepsPerSecond"] = 0,["averageStepTime"] = 0,["averageError"] = 0,["isRunning"] = false,}
参照してください:
戻り値
タスクスケジューラによって実行されたジョブに関する情報を含むテーブル、上記の形式を参照してください。
コードサンプル
Here is an example of iterating over the job info.
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
このメソッドは、指定されたコンテンツ URL に関連する Instances のアレイを返します。Roblox ライブラリからコンテンツを挿入するのに使用できます。この方法で Sounds を挿入することはできません、Instance に関連付けられておらず、コンテンツ URLのみがあるためです。
InsertService:LoadAsset() とは異なり、DataModel:GetObjects() はアセットが「信頼できる」ことを必要としません、つまりアセットはログインしたユーザーに所有されたり、Roblox によって作成されたりして挿入する必要はありません。ただし、アセットがログインしたユーザーによって所有されていない場合、それは自由に利用可能でなければなりません。
この機能のセキュリティコンテキストにより、プラグインまたはコマンドバーにのみ使用できます。For an alternative that can be used in Scripts と LocalScripts , see InsertService:LoadAsset() 。
パラメータ
指定されたコンテンツ URL。
戻り値
コンテンツ URL に関連する Instances の配列。
コードサンプル
If you want to view a plugin's source code without installing it, you can use DataModel:GetObjects() to download the plugin. The code sample below includes a function that will take a plugin's website URL and insert the plugin into the currently selected Instance or the Workspace.
Due to GetObjects' security context, this function can only be used in the command line or in a plugin.
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)
The content ID of a Decal on the Roblox website is associated with a Decal Instance rather than the actual content ID of the texture.
The code below, will use DataModel:GetObjects() to insert Decal objects into place and read their Decal.Texture property to obtain the image content IDs.
To use this code sample, enter the web URLs of the decals you'd like to convert into the array named IMAGES (as strings). A dictionary with the converted textures will be outputted.
local IMAGES = {
-- Insert Decal web URLs in an array here (as strings)
}
-- open the dictionary
local outputString = "textures = {"
-- utility function to add a new entry to the dictionary (as a string)
local function addEntryToDictionary(original, new)
outputString = outputString
.. "\n" -- new line
.. " " -- indent
.. '["'
.. original
.. '"]' -- key
.. ' = "'
.. new
.. '",' -- value
end
print("Starting conversion")
for _, webURL in pairs(IMAGES) do
-- get the content 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")
-- close the dictionary
outputString = outputString .. "\n}"
-- print the dictionary
print(outputString)
IsLoaded
ゲーム内のすべての最初の Instances がクライアントにレプリケーションを終えたとき、この関数は真に返します。
親になるまで ReplicatedFirst 、 LocalScripts はゲームがロードされるまで実行しません。次のスニペット、 から実行され、ゲームがロードされるまで生成されます:
if not game:IsLoaded() thengame.Loaded:Wait()end
参照してください:
- レプリケーション順序 により、ロードプロセスの詳細な概要。
- DataModel.Loaded , ゲームがロードされたときに発動するイベント
- Instance:WaitForChild() , 個々の Instance がロード終了を待たずに複製できるように使用できる機能
戻り値
クライアントがゲームを初めてロードしたかどうか。
コードサンプル
This sample demonstrates a custom loading screen with a basic TextLabel. The code should be placed in a LocalScript within ReplicatedFirst. To expand on this sample with loading screen animations, see the Custom Loading Screens article.
local Players = game:GetService("Players")
local ReplicatedFirst = game:GetService("ReplicatedFirst")
local player = Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
-- Create a basic loading screen
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
-- Parent entire screen GUI to player GUI
screenGui.Parent = playerGui
-- Remove the default loading screen
ReplicatedFirst:RemoveDefaultLoadingScreen()
--wait(3) -- Optionally force screen to appear for a minimum number of seconds
if not game:IsLoaded() then
game.Loaded:Wait()
end
screenGui:Destroy()
SetPlaceId
この機能は、ゲームインスタンスの DataModel.PlaceId を指定された placeId に設定します。
場所が公開されないときに、 と の両方を設定する必要があります、例えばローカルの ファイルです。下に例を見てください。Studio からのアクセスを獲得するには、 ゲーム設定パネルの セキュリティ パネルから Studio への API サービスへのアクセスを有効にする 設定が必要です。
local DataStoreService = game:GetService("DataStoreService")-- PlaceId を placeId、GameId を universeId に設定して、DataStore 'Data'にアクセスします。game:SetPlaceId(placeId)game:SetUniverseId(universeId)local dataStore = DataStoreService:GetDataStore("Data")
パラメータ
DataModel.PlaceId を設定するID。
戻り値
SetUniverseId
この機能は、現在のゲームインスタンスの DataModel.GameId を指定された universeId に設定します。ロブロックスに公開されていないローカル .rbxl ファイルをテストするときに便利です。
未公開の場プレースで DataStoreService にアクセスするには、両方の DataModel:SetUniverseId() と DataModel:SetPlaceId() が設定する定されなければなりません。
パラメータ
DataModel.GameId を設定するID。
戻り値
イベント
GraphicsQualityChangeRequest
ユーザーがホットキーを使用してグラフィック品質を増加または減少させるように促すと、ファイアが発生します。
このイベントは次の条件で発動します:
- ユーザーが F10 を押すと、このイベントは betterQuality 引数で true が発動します。
- ユーザーが Shift F10 を押すと、このイベントは betterQuality 引数の false で発動します。
このイベントは、現在のグラフィック品質レベルを提供したり、グラフィック品質のすべての更新をカバーしたりしません。たとえば、コア GUI エスケープメニューで行われた変更は登録されません。
次のスニペットを使用して、ユーザーの を取得できます:
UserSettings():GetService("UserGameSettings").SavedQualityLevel
ユーザーのグラフィック設定が自動に設定されている場合、Enum.SavedQualitySetting は Automatic になります。現在、開発者がユーザーのマシンの現在のグラフィック品質レベルを信頼性の高い方法で取得する方法はありません。
パラメータ
ユーザーがグラフィック品質を増加 ( true ) または減少 ( false ) に促したかどうか
コードサンプル
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)
Loaded
このイベントは、ゲーム内のすべての最初の Instances がクライアントにレプリケーションが終了したときにクライアントで発動します。
親になるまで ReplicatedFirst 、 LocalScripts はゲームがロードされるまで実行しません。次のスニペット、 から実行され、ゲームがロードされるまで生成されます:
if not game:IsLoaded() thengame.Loaded:Wait()end
参照してください:
- レプリケーション順序 により、ロードプロセスの詳細な概要。
- DataModel.Loaded , ゲームがロードされたときに発動するイベント
- Instance:WaitForChild() , 個々の Instance がロード終了を待たずに複製できるように使用できる機能