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

How do i detect when a players health cahnges then heal them?

Asked by 4 years ago

I am creating a admin thing and I want the admins to be able to regen when there heath changes.

0
Listen to an event named HealthChanged. It is a part of Humanoid. The first parameter is the new value of the Humanoid's health. pidgey 548 — 4y

2 answers

Log in to vote
1
Answered by 4 years ago

There is a .Changed event. You would use it like so:

function changed()
    player.Humanoid.Health = 100
end

instance.Changed:Connect(changed)
0
Just read the comment, if theres a HealthChanged event then you would replace .Changed with it. RunKittenzRComin 170 — 4y
0
The reason there is a HealthChanged event is because it includes the new Humanoid's health as a parameter, also, that script will change your health if ANYTHING changes in the Humanoid, which is incorrect.. pidgey 548 — 4y
Ad
Log in to vote
0
Answered by
Despayr 505 Moderation Voter
4 years ago
Edited 4 years ago

You will use the 'HealthChanged' function as stated above. If for some reason you have the health higher than 100, this will set it to the maxhealth

game:GetService("Players").PlayerAdded:Connect(function(plr)

    plr.CharacterAdded:Connect(function(char)

        local Humanoid = char:FindFirstChildOfClass("Humanoid")

        Humanoid.HealthChanged:Connect(function()

            Humanoid.Health = Humanoid.MaxHealth

        end)

    end)





end)



Answer this question