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.

3 comments
Good to go! thank you, I will take some time to learn to make my scripts neater.
Line 36?
Its in reference of OP's Post