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

How to add health to a humanoid when touching a brick?

Asked by
zomspi 541 Moderation Voter
5 years ago

I am trying to make a safe zone but I don't know how I would set the humanoid's health to 100 every time it got damaged.

1 answer

Log in to vote
0
Answered by 5 years ago

Assuming your "SafeZone" is a single part, you could do this:

ServerScript

local SafeZone = script.Parent

SafeZone.Touched:Connect(function(hit)
    if hit and hit.Parent and game:GetService("Players"):GetPlayerFromCharacter(hit.Parent) then
        hit.Parent:WaitForChild("Humanoid").Health = 100
    end
end)

You can also use the TakeDamage() function of Humanoids by using a negative number, where Line 5 would instead be

hit.Parent:WaitForChild("Humanoid"):TakeDamage(-100)
Ad

Answer this question