Load a Map
Lesson 5 of 18 in Coddy's Roblox Game: Disaster Survival course.
Rounds happen on a map. The maps wait in ServerStorage, a service whose contents are not in the world: nobody sees them or touches them. Open ServerStorage.Maps in the Explorer outline and you will find the Island.
A round puts a copy of a map in the workspace with Clone, and removes it afterwards with Destroy. The original stays in ServerStorage, untouched, ready for the next round:
local map = ServerStorage.Maps.Island:Clone()
map.Name = "Map"
map.Parent = workspace
-- ... the round ...
map:Destroy()A copy keeps the original's positions, so the island appears where it was built, far from the lobby. Moving the original instead of cloning it would work once: after the first Destroy there would be no Island left for round two.
Challenge
MediumMake each round load the Island:
- At the top, get
ServerStoragewithgame:GetService. - When the round starts (after the lobby countdown), clone
ServerStorage.Maps.Island, name the copyMapand parent it to the workspace. - When the round's countdown ends, destroy the map.
Press Play: when the round starts, the island appears far ahead of the lobby. Then Check.
Try it yourself
local Players = game:GetService("Players")
local Settings = require(game.ReplicatedStorage.Settings)
print("Rounds last " .. Settings.RoundLength .. " seconds")
-- Every player gets Wins on the leaderboard
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)
-- The status board in the lobby
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
-- The round loop
while true do
for seconds = Settings.Intermission, 1, -1 do
setStatus("Intermission: " .. seconds)
task.wait(1)
end
for seconds = Settings.RoundLength, 1, -1 do
setStatus("Time left: " .. seconds)
task.wait(1)
end
end
This lesson includes a short quiz. Start the lesson to answer it and track your progress.