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 5 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 — 5y

2 answers

Log in to vote
1
Answered by 5 years ago

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

1function changed()
2    player.Humanoid.Health = 100
3end
4 
5instance.Changed:Connect(changed)
0
Just read the comment, if theres a HealthChanged event then you would replace .Changed with it. RunKittenzRComin 170 — 5y
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 — 5y
Ad
Log in to vote
0
Answered by
Despayr 505 Moderation Voter
5 years ago
Edited 5 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

01game:GetService("Players").PlayerAdded:Connect(function(plr)
02 
03    plr.CharacterAdded:Connect(function(char)
04 
05        local Humanoid = char:FindFirstChildOfClass("Humanoid")
06 
07        Humanoid.HealthChanged:Connect(function()
08 
09            Humanoid.Health = Humanoid.MaxHealth
10 
11        end)
12 
13    end)
14 
15 
16 
17 
18 
19end)

Answer this question