ServerStorage
*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่
คอนเทนเนอร์ที่เนื้อหาสามารถเข้าถึงได้เฉพาะในเซิร์ฟเวอร์เท่านั้นวัตถุที่ลดลงจาก ServerStorage จะไม่ถูกส่งต่อไปยังไคลเอนต์และจะไม่สามารถเข้าถึงได้จาก LocalScripts
เนื่องจาก ServerStorage เป็นบริการจึงสามารถเข้าถึงได้โดยใช้วิธี DataModel.GetService เท่านั้น
โดยการจัดเก็บวัตถุขนาดใหญ่เช่นแผนที่ใน ServerStorage จนกว่าจะต้องใช้ การจราจรเครือข่ายจะไม่ถูกใช้เพื่อส่งวัตถุเหล่านี้ไปยังไคลเอนต์เมื่อพวกเขาเข้าร่วมเกม
Scripts จะไม่ทำงานเมื่อพวกเขาถูกผูกกับ ServerStorage แม้ว่า ModuleScripts จะอยู่ภายในและสามารถเข้าถึงและทำงานได้ขอแนะนำให้นักพัฒนาใช้ ServerScriptService เพื่อจัดเก็บ Scripts ที่พวกเขาต้องการให้เซิร์ฟเวอร์ดำเนินการ
โปรดทราบว่าเนื้อหาของ ServerStorage สามารถเข้าถึงได้เฉพาะโดยเซิร์ฟเวอร์เท่านั้น ดังนั้นเนื้อหาจะต้องถูกผูกไว้ที่อื่น (เช่น 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