how would I make this script restart if the player that is chosen ahs left? I have tried multiple times. Any help?

h = Instance.new("Hint",game.Workspace) maps = game.Lighting.Maps:GetChildren() players = game.Players:GetPlayers() winner = game.Workspace.winner

while true do wait(1) if #players >1 then h.Text = "Choosing the map.." wait(3) mapchoosing = math.random(1,#maps) mapchoosen = maps[mapchoosing] h.Text = "The map is named"..mapchoosen.Name mapchosenclone = mapchoosen:clone() mapchosenclone.Parent = game.Workspace wait(1) h.Text = "Choosing the player" wait(5) randplayer = math.random(1,#players) playerchosen = players[randplayer] h.Text = "The name of the player is" ..playerchosen.Name wait(1) playerchosen.Character.Torso.CFrame = CFrame.new(Vector3.new(43.088, 26.76, -333.25)) for t = 30,1,-1 do h.Text = "Time left"..t wait(1) end

function RestartScript()
script:Clone().Parent = Game.ServerScriptService -- clone the script so it restarts

script:Destroy() -- disconnect all events in this one so it doesn't do unexpected things

playerchosen.Character.Humanoid.Died:connect(RestartScript) -- if the player dies

playerchosen.AncestryChanged:connect(RestartScript) -- if the player disappears from the game wait(1)

	end
	wait(1)
	mapchosenclone:remove()
else
	h.Text = "There isnt enough players to start"
	
end

end

2 comments

0

Put the entire script in the code block please.

0

how?