ServerStorage
*このコンテンツは、ベータ版のAI(人工知能)を使用して翻訳されており、エラーが含まれている可能性があります。このページを英語で表示するには、 こちら をクリックしてください。
サーバー上でのみアクセス可能なコンテンツのあるコンテナ。ServerStorage から降りるオブジェクトは、クライアントに複製されず、LocalScripts からアクセスできません。
サーバーストレージはサービスなので、DataModel.GetService メソッドを使用してのみアクセスできます。
マップなどの大きなオブジェクトを ServerStorage に保存し、必要になるまで使用しないと、ゲームに参加するときにこれらのオブジェクトをクライアントに送信するネットワークトラフィックが使用されません。
Scripts は、ServerStorage に親属されているときに実行されませんが、ModuleScripts 内に含まれているものにアクセスして実行できます。開発者は、ServerScriptService を使用して、サーバーが実行することを望む Scripts を保持することをお勧めします。
サーバーストレージのコンテンツは、サーバーからのみアクセスできるため、クライアントがアクセスできる前に、他の場所(例: Workspace)に親階層化する必要があります。サーバーとクライアントの両方にアクセスできるコンテナが必要な開発者は、代わりに ReplicatedStorage を使用することをお勧めします。
コードサンプル
This is a very simple example of how a multiple map system can be made using ServerStorage.
It creates three dummy models (to take the place of maps), that are parented to ServerStorage. Then, it will load a random map (different to the previous map) and wait a specified duration on a loop.
Developers wishing to integrate something similar into their games should consider measures to ensure players respawn correctly, or go to a lobby during intermission periods.
local ServerStorage = game:GetService("ServerStorage")
local ROUND_TIME = 5
local map1 = Instance.new("Model")
map1.Name = "Map1"
map1.Parent = ServerStorage
local map2 = Instance.new("Model")
map2.Name = "Map2"
map2.Parent = ServerStorage
local map3 = Instance.new("Model")
map3.Name = "Map3"
map3.Parent = ServerStorage
local maps = { map1, map2, map3 }
local RNG = Random.new()
local currentMap = nil
local lastPick = nil
while true do
print("New map!")
-- remove current map
if currentMap then
currentMap:Destroy()
end
-- pick a map
local randomPick = nil
if #maps > 1 then
repeat
randomPick = RNG:NextInteger(1, #maps)
until randomPick ~= lastPick
lastPick = randomPick
end
-- fetch new map
local map = maps[randomPick]
currentMap = map:Clone()
currentMap.Parent = workspace
task.wait(ROUND_TIME)
end