Menu
CoddyTech

Load a Map

Lesson 5 of 20 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 icon

Challenge

Medium

Load the Island for every round.

  1. At the top, get ServerStorage with game:GetService.
  2. After the lobby countdown, clone ServerStorage.Maps.Island into local map, name it Map and parent it to the workspace.
  3. When the round's countdown ends, call map:Destroy().

Press Play: when the round starts the island appears far ahead of the lobby, and it vanishes when the round ends. 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

	-- Lesson 5: Load a Map goes here
	for seconds = Settings.RoundLength, 1, -1 do
		setStatus("Time left: " .. seconds)
		task.wait(1)
	end
end

All lessons in Roblox Game: Disaster Survival

Practice on your own: Roblox playground