I am trying to make this weapon that heals the player when their HP hits or is below a certain number, but the thing is, I keep getting an error. The error states that Humanoid is not a valid member of backpack. I've tried doing something like this before, but it worked perfectly. It is a normal script, and it is not a local script, although I have tried to convert it to local, and it still didn't work. What am I doing wrong?
script.Parent.Parent.Humanoid.HealthChanged:connect(function(hp) if hp <= 0.01 then print("Heal the player!") script.Parent.Parent.Humanoid.Health = 10 wait(0.1) end end)
Not for sure where you are getting at, but this may help:
local wfc = game.WaitForChild local player = game.Players.LocalPlayer local phum = wfc(player.Character,"Humanoid") phum.Changed:connect(function() --detection of health change if phum.Health == 0 or phum.Health < 1 then phum.Health = 10 end end)
This script can really work anywhere you put it, so I hope this helps.