Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Having trouble creating a healing animation?

Hello everyone! I am new to scripting, and I've tried to create a potion script. Basically, if your health is below 50, you can press a certain key to heal yourself. The problem is that I don't know how to create one, so I've tried doing this:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local animation = Instance.new("Animation")
animation.AnimationId = "assetidhere"
local character = player.Character
local humanoid = game.Players.LocalPlayer.Character.Humanoid
local animationHealth = 50


if player.character.humanoid.Health > 50 then
humanoid.animationHealth:connect(function(health)
	local change = math.abs(currentHealth + animationHealth)

mouse.KeyDown:connect(function(key)
	if key == "h" then 
        animation.Play()
		wait (5)
		animation.Stop()
	

end)

Could someone please tell me how I would do something like this, as I can't get it to work? Thank you for your time. I purposely removed the asset id, so that is not the problem. Again, thanks you for your time.

1 answer

✓ Accepted answer

First of all your missing a end after line 36. I also recommend you learn to make your code nice a neat for example if you have something nested a statement like If or while or something like that indent it by hitting your tab key. Anyways I think I fixed it so hopefully it works for you.


if player.character.humanoid.Health > 50 then
	humanoid.animationHealth:connect(function(health)
    local change = math.abs(currentHealth + animationHealth)

	mouse.KeyDown:connect(function(key)
    if key == "h" then 
        animation.Play()
        wait (5)
        animation.Stop()
	end


end)

3 comments

0

Good to go! thank you, I will take some time to learn to make my scripts neater.

0

Line 36?

0

Its in reference of OP's Post

This discussion is preserved as it was. New answers, comments, and votes are closed.