I'm trying to make a fighting game and when a playing dies in a random map, the player spawns back in the map. I tried to make if the health reaches 0, the player spawns back to the map. However, it didn't work. This is just a part of the script.
local randomMap = maps[math.random(1, #maps)]
randomMap:Clone().Parent = workspace
CurrentMap = randomMap.Name
status.Value = "Chosen game is "..randomMap.Name
wait(3)
local plrs = game.Players:GetChildren()
for i = 1, #plrs do
local randomSpawn = spawns[math.random(1, #spawns)]
plrs[i].Character.HumanoidRootPart.CFrame = CFrame.new(randomSpawn.Position)
end
for i = 1, #plrs do
local randomSpawn = spawns[math.random(1, #spawns)]
if plrs[i].Character.Humanoid.Health == 0 then
plrs[i].Character.HumanoidRootPart.CFrame = CFrame.new(randomSpawn.Position)
end
end
Sec = 30
repeat
Sec = Sec -1
status.Value = Sec.." seconds left!"
wait(1)
until Sec == 0
for i = 1, #plrs do
plrs[i].Character.HumanoidRootPart.CFrame = workspace.Lobby.SpawnLocation.CFrame + Vector3.new(0, 10, 0)
end
workspace[CurrentMap]:Destroy()
end
