How would I change this so it restarts the game once there is a winner, and teleports everyone back to the lobby for intermission?

local replicatedstorage = game:GetService('ReplicatedStorage')
local status = replicatedstorage:WaitForChild('InfoValue')
local mapstorage = game.Workspace:WaitForChild('mapStorage')
while true do
 game.Workspace.Sad:Play()
while game.Players.NumPlayers < 2 do
status.Value = "Not Enough Players! :( (2 or More)"
repeat 
	wait(2) 
	until game.Players.MaxPlayers > 2
end
_G.gameplayers = {}
for i = 15,0,-1 do
	game.Workspace.Sad:Stop()
	game.Workspace.Music:Play()
	status.Value = "Intermission:"..i
	wait(1)
	_G.gameplayers = {}


 for i ,v in pairs(game.Players:GetPlayers()) do
if v then
	 table.insert(_G.gameplayers, v.Name)
end
end

game.Workspace.Music:Stop()
 local mapsinserverstorage = game:GetService('ServerStorage'):GetChildren()
local chosenmap = mapsinserverstorage[math.random(1,#mapsinserverstorage)]
chosenmap:Clone() .Parent = mapstorage
status.Value = "Teleporting Fighters"
wait(1)
local spawns = chosenmap:WaitForChild('Spawns'):GetChildren()
for _, player in pairs(game.Players:GetPlayers()) do
if player and #spawns > 0 then
	local torso = player.Character:WaitForChild('Torso')
	local allspawns = math.random(1,#spawns)
	local randomspawn = spawns[allspawns]
	if randomspawn and torso then table.remove(spawns,allspawns)	
	torso.CFrame = CFrame.new(randomspawn.Position + Vector3.new(0,2,0))
	local sword = game.ReplicatedStorage.BasicSword
	local newsword = sword:Clone ()
	newsword.Parent = player.Backpack
	end
end
end




game.Workspace.Battle:Play()

for i = 90,0,-1 do

	status.Value = i.." Seconds Left"
if i == 0 then 
status.Value = "Time Up!"
for _, player in pairs (game.Players:GetChildren()) do
if player:FindFirstChild('leaderstats') then
	player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 2
end
end
break
else
end

for i = 90,0,-1 do 

if i == 0 then
status.Value = "Time Up!"

break
end	

wait(1)
if #_G.gameplayers == 1 then 
for i,v in pairs (_G.gameplayers) do
	if v ~= nil then 
		status.Value = v.." is the Winner!"
		game.Players[v].leaderstats.Cash.Value = game.Players[v].leaderstats.Cash.Value + 10
		break
		
	end
end
break
else
	status.Value = i.."Seconds Remaining!"
end
end
mapstorage:ClearAllChildren()
wait(5)
end



end

5 comments

0

As a general rule of thumb, you never actually use the map/object you play on. Instead, you call ":Clone()" on that map/object and when you are done, simply :Destroy() it.

0

?

0

You put the map in something like ReplicatedStorage and then clone it into workspace. For example: game.ReplicatedStorage.Part:Clone().Parent = workspace

0

Ok? It is like that? The maps are in replicated storage

0

help?