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

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

Asked by 6 years ago

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

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

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

0
Use HealthChanged instead, but this answer isn't that bad User#24403 69 — 6y
0
Changed detects the Animation being used, not the Health being changed DeceptiveCaster 3761 — 6y
0
So this answer is 100% wrong DeceptiveCaster 3761 — 6y
Ad
Log in to vote
-1
Answered by 6 years ago

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

Answer this question