Script randomly kills players

https://hastebin.com/vixedureba.lua

above is my code
i have an issue where sometimes it kills a player with no reason resulting in the other player to win
can anyone help me fix this issue?

1 Like

Do you think you could give me the specific part of code that might possibly trigger this? I am currently reading your code and the only ways I am thinking of your character randomly dying are after the round and during the teleportation.

1 Like

the death only happens when the round starts, which would mean its over here:

if #Survivor:GetPlayers() == 1 then
					for i,v in pairs(game.Teams["Playing"]:GetPlayers()) do
						v.leaderstats.Cash.Value += 1
						
						for _, Player in pairs(game.Players:GetChildren())do
							if Player.Character and Player.Character:FindFirstChild('Humanoid') then
								Player.Character.Humanoid.Health = 0
							end -- if Player.Character and Player.Character:FindFirstChild('Humanoid') then
						end -- for _, Player in pairs(game.Players:GetChildren())do
						
						countdown = 2
						for i = countdown, 1, -1 do
							ChosenMap:Destroy()
							RoundStatus.Value = "Round over!"
							GameStatus.Value = i + 3
							local winner = game.ReplicatedStorage.Winner
						winner.Value = v.Name
						wait(1)
						end -- for i = countdown, 0, -1 do
						
						countdown = 3
						for i = countdown, 0, -1 do
							ChosenMap:Destroy()
							RoundStatus.Value = v.Name.." has won!"
							GameStatus.Value = i
							local winner = game.ReplicatedStorage.Winner
							winner.Value = v.Name
							wait(1)
						end -- for i = countdown, 0, -1 do
						
					end -- for i,v in pairs(game.Teams["Playing"]:GetPlayers()) do
					break
			end -- if #Survivor:GetPlayers() == 1 then

Here is where a player gets killed

Player in pairs(game.Players:GetChildren())do
							if Player.Character and Player.Character:FindFirstChild('Humanoid') then
								Player.Character.Humanoid.Health = 0
1 Like

i know but i dont think that part of the code should be killing when a round starts cause its under the if statement checking for 1 player left

If anything, your killing all of the playing players even though there is only one playing player left. Why so?

Shouldn’t you check if there is one survivor left, then instead kill everyone surviving?

thats just a bodge ive made to get the core working

A what? I didn’t understand you.

bodge just means to make a quick or temporary fix or solution

Well this “bodge” you did may be the source of your problem.

Instead of killing everyone in the lobby when there is one person left, I recommend just killing the last person alive on the Survivor team and teleporting the rest to spawn (assuming dying puts you in the lobby)

but my issue is that players are dying while still alive during a round

like my issue is that players sometimes die as soon as the round starts and causes the round to end

found the issue there was something wrong with teams