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

Heal script that heals player when the developer product is bought?

Asked by 10 years ago

I have tried this, but it doesn't work. I'm not sure this is how it's supposed to be :/

script.Parent.Humanoid.Changed:connect(function(p) 
if p == "Health" then 
if script.Parent.Humanoid.Health < script.Parent.Humanoid.MaxHealth then 
script.Parent.Humanoid.Health = script.Parent.Humanoid.Health +1
wait(2) 
end 
end 
end)

0
Remember to indent code, it looks nicer :) Ekkoh 635 — 10y

1 answer

Log in to vote
0
Answered by
Ekkoh 635 Moderation Voter
10 years ago

Unless you've already scripted the developer product logic somewhere else, you'll need to do that.

  1. I'd suggest using the HealthChanged event rather than the Changed event
  2. This will only heal the character every time the health changes which I'm assuming isn't what you were going for. You probably want a loop to heal the character to max health.
local hum = script.Parent
hum.HealthChanged:connect(function()
    while hum.Health < hum.MaxHealth do -- won't start if character is already at max health
        hum.Health = hum.Health + 1
        wait(2)
    end
end)
Ad

Answer this question