How to make a healing system as it is descriptive

hello, so i want to make a healing system which when the player presses a text button then an animation will be done and wait 3 seconds and heal but if for some reason he moves during those 3 seconds the animation stops and he doesn’t heal . I DON’T WANT A SCRIPT ONLY THAT YOU TELL ME HOW I DO IT AND WHAT MODULES I SHOULD USE. If I don’t answer, it’s because I’m sleeping. I’ll answer around 9 am when I get up.

1 Like

So, you want to set up your button like this:
1 Script, 1 LocalScript, 1 RemoteEvent, and The Animation
image

In the Local Script you want this code:

local Button = script.Parent -- Assigns a variable to the button
local db = false -- This is a cooldown, we will use it later so you cant spam
local Event = script.Parent.RemoteEvent -- This assigns a variable to the remote event

Button.MouseButton1Click:Connect(function() -- a function when the button is clicked
	if db == false then -- checks if the cooldown is false
		db = true -- makes the cooldown true
		Event:FireServer() -- fires the remote event
		wait(4) -- waits 4 seconds
		db = false -- sets the cooldown back to false
	end
end)

In the Script you want this code:

local Event = script.Parent.RemoteEvent -- Assigns the event to a variable
local Anim = script.Parent.Animation -- Assigns the animation to a variable
local Amount = 10 -- Change this to whatever amount you want healed

Event.OnServerEvent:Connect(function(player) -- A function for when the remote event is fired, getting the player
	local Animation = player.Character.Humanoid:LoadAnimation(Anim) -- Turning the animation into a track
	Animation:Play() -- playing the animation track
	wait(3) -- waiting 3 seconds
	Animation:Stop() -- stopping the animation track
	if player.Character.Humanoid.Health + Amount <= 100 then -- Checking if the player has less than the amount to heal
		player.Character.Humanoid.Health = player.Character.Humanoid.Health + Amount -- adding to his health
	else -- checking if not
		player.Character.Humanoid.Health = 100 -- setting his health to 100, because it was 91 or above.
	end
end)

If this helped make sure to check it as the answer :blush:

2 Likes

Thank you for taking the trouble to make the code without me asking you and it really worked for me thank you very much

1 Like

hey I know this topic is over but if you want help me with this topic:

It looks like the topic was solved, thanks it’s no biggie!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.