Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why Is my Code not Working?

I am trying to spawn a map, with this code:

	statustag.Value = "Loading Map"
	timertag.Value = -1
	mapholder:ClearAllChildren()
	wait(2)
	local allmaps = maps:GetChildren()
	local newmap = allmaps[math.random(1, #allmaps)]:clone()
	newmap.Parent = mapholder
	wait(2)

Which is in a while true do loop, with an end and all. But, when the map spawns, it disapears right afterwards, killing the players.

1 comment

0

I have bonus stuff in there too.

1 answer

✓ Accepted answer

You forgot to let the script know whether or not the game ended.

Use a BoolValue for a game running (or anything else really) to get the script to wait until the game ends to unload the map and teleport the players.

statustag.Value = "Loading Map"
timertag.Value = -1
mapholder:ClearAllChildren()
wait(2)
local allmaps = maps:GetChildren()
local newmap = allmaps[math.random(1, #allmaps)]:clone()
newmap.Parent = mapholder
repeat wait() until game.ServerStorage.GameRunning = false --Something like that

How you change GameRunning or whatever you want to use for the game status is up to you, and should just be a matter of fine-tuning your other scripts. Hope i helped you with that!

This discussion is preserved as it was. New answers, comments, and votes are closed.