Tool that when you click if slowly heals you and plays an animation

I would like to create this tool where when you click you play an animation that slowly heals you until you click again

And I would like to know how could I make this possible example what variables, functions, etc do I need to use

image
The tool looks like this

Your tool will need a local script.

It will have to listen to some events. Check out the Tool Documentation:
https://developer.roblox.com/en-us/api-reference/class/Tool

If you look in the event section, there are around 3 events you are interested in:
Equipped, Unequipped, and Activated.

Next, you will need to toggle a bool variable when you click. You can do this very simply by doing:

-- somewhere near the top
IsHealing = false

-- later

Tool.Activated:Connect(function()
    IsHealing = not IsHealing -- this will flip it to true and false every click
    if isHealing then
        -- PLAY ANIMATION HERE
    else
        -- STOP PLAYING ANIMATION
    end
end)

Note that above code is simply pseudo code and you will have to make it work.

To play an animation, you need to create an animation in Roblox Stuido and upload it. Once you do so, create an Animation object and call LoadAnimation on an Animator object (these will be inside of your Humanoid.)

Here’s some useful links:

The last thing is the actual healing.

You can create a while loop at the very bottom of the script. When IsHealing is true, simply Heal x amount to the player.

Good luck. :slight_smile:

Edit: I forgot that to heal, you will need the Server to do so. You need a Script on a server and will need to use RemoteEvent to talk to it.

1 Like

Does
Tool.Activated:Connect(function()
Mean when you click with the tool active?

Ninja_Deer gave you all you needed without giving you the entire code but if you are stuck with the loop here is some code that may help.

In the loop you can do
Humanoid.Health += Humanoid.MaxHealth x 0.01

You can change the values and the speed of the loop to slowly heal the player involving that line of code. I would also add a check to make sure they don’t go over max by doing

if Humanoid.Health > Humanoid.MaxHealth then
Humanoid.Health = Humanoid.MaxHealth
end

1 Like

That’s right. There’s also a deactivated event. I would look on the documentation a lot and read each description before you use it. It explains both of these methods.

1 Like