My end goal is to run a snippet of code for each player which the bool value named “safe” in their player model is set to false.
The issue here is that the while loop suddenly stops after this line of code: if plr.Character:WaitForChild('Humanoid', 1).Health >= 0 then return end
without any error in console related to the script. Here’s my entire loop for context.
wait(1)
print('doing for loop')
for i, plr in pairs(game:GetService("Players"):GetPlayers()) do
print(plr.Name)
if plr:WaitForChild('safe', 1).Value == false then
print('not safe')
if not plr.Character then return end
print('has character')
if not plr.Character:WaitForChild('Humanoid', 1) then return end
print('has humanoid')
if plr.Character:WaitForChild('Humanoid', 1).Health >= 0 then return end
print('not dead')
plr:WaitForChild('time', 1).Value += 1
plr.Character:WaitForChild('Head'):WaitForChild('NameGUI', 1).name.Text = plr:WaitForChild('time', 1).Value
players[plr.UserId].timeval = plr:WaitForChild('time', 1).Value
end
end
end
I’ve tried things like adding WaitForChild
, separating my one if statement to find which part was stopping the while loop (I used to have all of those statements in one long one), checking to see if the humanoid even exists, etc. I’d expect an error at the very least, but it simply stops, with it’s last output being
doing for loop
cheslin23t
not safe
has character
has humanoid
The funny thing is, if one of the earlier if statement returns before it ever gets to the if statement in question (checking if the character is alive), the loop would continue running. I am looking for a working solution, but I’d also like to know why that specific line wouldn’t work correctly, or at least provide an error. Thank you.