Is their anyway to make this more efficient? This is located inside the workspace. Sometimes it will say that the humanoid is nil. I put if ~= nil
, but that don't work.
while true do wait() local Players = Game.Players:GetChildren() for i = 1, #Players do if Players[i].Character.Humanoid.Health == 0 then end end end
Try this;
while wait(0) do local Players = Game.Players:GetChildren() for i = 1, #Players do if Players[i].Character:FindFirstChild("Humanoid")then --If Script finds Humanoid if Players[i].Character.Humanoid.Health == 0 then end end end end
I hope this helped!
I believe that this way (using a function triggered by the death) is more efficient than a while or for loop.
game.Players.PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(character) character:WaitForChild("Humanoid").Died:connect(function() --Then I believe you would do what you want here end) end) end)
Hope it helped!