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

Humanoid Health Checking Loop?

This is supposed to check the health of a humanoid until it is equal to zero, then it changes the player to a different team. The loop doesn't seem to be firing. Is there something I am doing wrong? Thank you! :)

local player = game.Players.LocalPlayer
local name = game.Players.LocalPlayer.Name
local gethumanoid = game.workspace.name.FindFirstChild("Humanoid")



repeat
	print ("Player is healthy")
	wait (1)
		until gethumanoid.Health == 0
		player.TeamColor = BrickColor.new("Dark stone grey")

3 comments

0

gethumanoid.Died:connect(function()

0

Personally would use Humanoid.Died:connect(function) unless you want to watch the steps of their health

0

It worked for me for the dummies that I had, I deleted the local functions and changed the code a bit. Just what I needed thanks!

1 answer

✓ Accepted answer

I've added a function to make the script run when triggered.

wait(1)
local player= game:GetService("Players").LocalPlayer
local character= player.Character
local humanoid= character.Humanoid

function health()
	if humanoid.Health ~= 0 then
		print("Human is healthy")
	elseif humanoid.Health <= 0 then
		print("Human is ready for organ harversting") -- This was just a joke
		player.TeamColor = BrickColor.new("Dark stone grey")
	end
end
humanoid.HealthChanged:connect(health) -- If the players health is changed it will trigger the function
health()

If you want to keep using your old script I've fixed it below. BUT BE AWARE, IT MAY CAUSE LAG BECAUSE ITS CONSTANTLY RUNNING.

wait(1)
local player = game.Players.LocalPlayer
local name = game.Players.LocalPlayer.Name
local gethumanoid = game.workspace[name]:FindFirstChild("Humanoid")



repeat
    print ("Player is healthy")
    wait (1)
        until gethumanoid.Health == 0
        player.TeamColor = BrickColor.new("Dark stone grey")

1 comment

0

thanks my man. u tha real MVP.

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