ROUND system errors

Hello all have a game and it works fine until the end.I need so when all the players die it stops and when one player is left he is killed.

```

ReplicatedStorage.UnAnchorerEvent.OnServerEvent:Connect(function()
local PlayerList = game.Players:GetPlayers()

for i , v in pairs(PlayerList) do
	repeat wait() until v.Character
	v.Character.HumanoidRootPart.Anchored = false
end


local TheValue = ReplicatedStorage.GameOngoingFolder.GameOngoingValue
local Event = ReplicatedStorage.GameOngoingFolder.GameOngoingEvent

for i = 180 , 0 , -1 do
	TheValue.Value = i
	Event:FireAllClients()
	wait(1)
end
local PlayersInGame = 0

for i , v in pairs(PlayerList) do
	if v.RoundResult.Value == "InProgress" then
		PlayersInGame = PlayersInGame + 1
	end
end
if PlayersInGame == 1 then
	for i , v in pairs(PlayerList) do
		if v.RoundResult.Value == "InProgress" then
			local TheWinner = v.Name
			game.Players:FindFirstChild(TheWinner).leaderstats.Coins.Value += 10
			game.ReplicatedStorage.WinnerDisplayerEvent:FireAllClients(TheWinner)
			for i , v in pairs(PlayerList) do
				repeat wait()until v.Character
				v.Character:WaitForChild("Humanoid").Health = 0
			end
		end
	end
end


script.Disabled = true
script.Parent.IntermissionTimer.Disabled = false

end)

– This is an example Lua code block
```

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

need help???

Your script was a bit hard to figure out, though i think this should work for what you are looking to do

Script
local PlayerList = {}
ReplicatedStorage.UnAnchorerEvent.OnServerEvent:Connect(function()
PlayerList = game.Players:GetPlayers()

for i , v in pairs(PlayerList) do
	repeat wait() until v.Character
	v.Character.HumanoidRootPart.Anchored = false
end


local TheValue = ReplicatedStorage.GameOngoingFolder.GameOngoingValue
local Event = ReplicatedStorage.GameOngoingFolder.GameOngoingEvent

for i = 180 , 0 , -1 do
	TheValue.Value = i
	Event:FireAllClients()
	if #PlayerList <= 1 then continue end
	wait(1)
end

for i , v in pairs(PlayerList) do
	if v.RoundResult.Value == "InProgress" then
		v.leaderstats.Coins.Value += 10
		game.ReplicatedStorage.WinnerDisplayerEvent:FireAllClients(v.Name)
		for i , v in pairs(PlayerList) do
			repeat wait()until v.Character
			v.Character:WaitForChild("Humanoid").Health = 0
		end
	end
end

script.Disabled = true
script.Parent.IntermissionTimer.Disabled = false
end)

game.Players.PlayerAdded:Connect(function(player)
	player.Character:WaitForChild("Humanoid").Died:Connect(function()
		if table.find(PlayerList,player) then
			table.remove(table.find(PlayerList,player))
		end
	end)
end)
game.Players.PlayerRemoving:Connect(function(player)
	if table.find(PlayerList,player) then
		table.remove(table.find(PlayerList,player))
	end
end)

basically what i did was add a way for a player.character.died, and a player.removing event to change the playerlist, and if your left with 1 or less that 1 player (incase somehow everyone died/left) it will do the ending part.

1 Like