Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Humanoid Health Checking Loop?

Asked by 7 years ago

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")
0
gethumanoid.Died:connect(function() User#2146 0 — 7y
0
Personally would use Humanoid.Died:connect(function) unless you want to watch the steps of their health Bellyrium 310 — 7y
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! XbloxKing21 0 — 4y

1 answer

Log in to vote
4
Answered by
DeepDev 101
7 years ago

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")
0
thanks my man. u tha real MVP. marsupicide 60 — 7y
Ad

Answer this question