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.
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!