Menu
CoddyTech

加载地图

Coddy Roblox 游戏:灾难生存 课程的第 5 课,共 20 课。

每一轮都在地图上进行。地图存放在 ServerStorage 中,这是一个内容不属于游戏世界的服务:没人能看到或触碰这些内容。在 Explorer 大纲中打开 ServerStorage.Maps,你就会找到 Island。

每一轮开始时,都会用 Clone 将地图的副本放入工作区,并在之后用 Destroy 将其移除。原始地图会留在 ServerStorage 中,不受影响,为下一轮做好准备:

local map = ServerStorage.Maps.Island:Clone()
map.Name = "Map"
map.Parent = workspace

-- ... 这一轮 ...

map:Destroy()

副本会保留原始地图的位置,因此岛屿会出现在它建造时所在的位置,远离大厅。如果移动原始地图而不是克隆它,这种做法只能生效一次:第一次调用 Destroy 后,第二轮就没有 Island 了。

challenge icon

挑战

中等

每一轮都加载 Island。

  1. 在顶部,使用 game:GetService 获取 ServerStorage。
  2. 大厅倒计时结束后,将 ServerStorage.Maps.Island 克隆到 local map,将其命名为 Map,并将其设为 workspace 的子级。
  3. 本轮倒计时结束时,调用 map:Destroy()。

按“开始”:回合开始时,岛屿会出现在大厅前方远处;回合结束时,岛屿会消失。然后按“检查”。

亲手试试

local Players = game:GetService("Players")
local Settings = require(game.ReplicatedStorage.Settings)

print("Rounds last " .. Settings.RoundLength .. " seconds")

-- 每位玩家的排行榜上都有 Wins
Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local wins = Instance.new("IntValue")
	wins.Name = "Wins"
	wins.Parent = leaderstats
end)

-- 大厅里的状态板
local gui = Instance.new("SurfaceGui")
gui.Parent = workspace.StatusBoard

local status = Instance.new("TextLabel")
status.Name = "Status"
status.Size = UDim2.fromScale(1, 1)
status.BackgroundColor3 = Color3.fromRGB(25, 25, 35)
status.TextColor3 = Color3.fromRGB(255, 255, 255)
status.TextScaled = true
status.Text = "Welcome to Disaster Survival!"
status.Parent = gui

local function setStatus(text)
	status.Text = text
end

-- 回合循环
while true do
	for seconds = Settings.Intermission, 1, -1 do
		setStatus("Intermission: " .. seconds)
		task.wait(1)
	end

	-- 第 5 课:在这里加载地图
	for seconds = Settings.RoundLength, 1, -1 do
		setStatus("Time left: " .. seconds)
		task.wait(1)
	end
end

Roblox 游戏:灾难生存中的所有课

自己练习: Roblox 在线编辑器