I'm working on a healing spell, and I cant seem how to figure out how to heal the player. When I click, it prints what I want it to, but doesn't heal. I think I probably am missing a few things in my code. I tried the wiki but cant seem to find the solution to my problem. here is my code
local tool = script.Parent local field = nil local character = tool.Parent local human = character:FindFirstChild("Humanoid") function heal() if (human ~=nil) then human.Health = human.Health + 25 end end tool.Activated:Connect (function() heal() print ("healed") end)
I'm not asking for anyone to rewrite it, just point out what I messed up/missed out. Thanks in advance! :)
The problem is in line 3, when the script is first run, the tools parent will be the backpack. The tools parent won't be the character until you equip the tool. Just do this below
local tool = script.Parent local field = nil local player = game.Players.LocalPlayer local character = player.Character --The problem was here. I changed it for you local human = character:FindFirstChild("Humanoid") function heal() if (human ~=nil) then human.Health = human.Health + 25 end end tool.Activated:Connect (function() heal() print ("healed") end)