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

does anyone know how to make a script run everytime a local players health reaches a certain value?

yes, i dont know how to do this.

basically, i need to know how i can run a script "every time" my localplayers health 20.

so something like this, but i need it to do this every time when i re spawn or reset.

local humanoid = game:GetService("Players").LocalPlayer:GetCharacter().Humanoid if humanoid.Health >= 5 then FunctionName() end

2 answers

LocalScript:

local hum = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")

hum.Changed:Connect(function()
if hum.Health >= 20 then
--Do something
end
end

Not sure if this is what you're looking for but here you go

tell me if you have a problem

3 comments

0

Use HealthChanged instead, but this answer isn't that bad

0

Changed detects the Animation being used, not the Health being changed

0

So this answer is 100% wrong

To check if a condition has changed, you would need to use the loop, while true do. Basically what this does is run the script over and over until the specific condition changes. When it changes you can either break the script with the 'Break' or let it continue.

local player = game.Players.LocalPlayer local character = player.Character or player.CharacterAdded:Wait() local humanoid = character:WaitForChild("Humanoid")

while true do wait() if humanoid.Health >= 5 then end

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