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

Having trouble creating a healing animation?

Asked by 7 years ago

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

Log in to vote
0
Answered by 7 years ago

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)
0
Good to go! thank you, I will take some time to learn to make my scripts neater. Stephanie_Angela 2 — 7y
0
Line 36? jotslo 273 — 7y
0
Its in reference of OP's Post TheTiredHippo 30 — 7y
Ad

Answer this question