Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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)

1 comment

0

Thanks that worked. I keep doing game.parent for some reason.

This discussion is preserved as it was. New answers, comments, and votes are closed.