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

My gear does not work and there is no error. How do I fix this?

Asked by 2 years ago

I am new to scripting and making gear, so I might have done a obvious mistake. I'm trying to make a healing apple, but my script does not work and there no error in the output. This is my code

local tool = game.Parent

local function OnActivate()
    print("Player Healed")
    local character = tool.parent
    local humanoid = character.Humanoid
    humanoid.Health = humanoid.Health + 20
    tool:Destroy()
end

local function OnDeactivate()
    print("Player has been healed")
end


tool.Activated:Connect(OnActivate)

1 answer

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

if think you should do

local tool = script.Parent

not

local tool = game.Parent

the reason I think its script parent is Im guessing the script is in the tool so basically I think this would work better (this calls OnDeactivate from OnActivate)

local tool = script.Parent

local function OnDeactivate()
    print("Player has been healed")
end

local function OnActivate()
    print("Player Healed")
    local character = tool.parent
    local humanoid = character.Humanoid
    humanoid.Health = humanoid.Health + 20
    tool:Destroy()
end

tool.Activated:Connect(OnActivate)
0
Thanks that worked. I keep doing game.parent for some reason. nicemorew 26 — 2y
Ad

Answer this question