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.
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)