Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Output repeating lines of code instead of once?

Hio. I'm trying to get the output to print whether or not players are still alive or have died only once. Instead, it prints it repeatedly. I am using a server-side script for this.

--ROUND TIMER
for t = 120,0,-1 do --NORMAL TIME IS 120 SECONDS
	RoundTimerText.Value = ("%d:d"):format(math.floor(t/60),t%60)
	wait(1)
end

--Create a table of the current players playing for the SurvivorGUI later
for p = 1, #Players do
if Players[p].Character.Humanoid.Health == 0 then
		print("Dead")
elseif Players[p].Character.Humanoid.Health == 100 then
	print("Still alive")
	end
end

2 comments

0

It is printing multiple times because you have several players, and it is printing for each player if they are dead or alive.                                                                                                                                                                                         I would not recommend looking at their health to see if they are dead or alive, because on

0

I've been testing this with Play Solo...

1 answer

✓ Accepted answer

You should do this instead:

for _,v in pairs (game.Players:GetChildren) do
	if not v.Character then return end -- if the player does not have a character, they will be excluded
	v.Character:WaitForChild("Humanoid").Died:connect(function() -- when they die
		print("Dead")
	end)
end

This discussion is preserved as it was. New answers, comments, and votes are closed.