New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

Tool | attempted to index local 'equip' (a nil value) What did I do wrong?

Asked by
N43FGXL 12
12 days ago

I'm not sure what I did wrong. I get an error when doing these functions to my tool.

local tool = script.Parent.Parent

tool.Equipped:Connect(function(equip)
    local humanoid = equip:FindFirstChild("Humanoid")
    if (humanoid ~= nil) then
        humanoid.Health = 50
    end
end)

tool.Unequipped:Connect(function(equip)
    local humanoid = equip:FindFirstChild("Humanoid")
    if (humanoid ~= nil) then
        humanoid.Health = 100
    end
end)

2 answers

Log in to vote
0
Answered by
Azarth 2741 Moderation Voter Community Moderator
12 days ago
Edited 12 days ago

Equipped and Unequipped pass the LocalPlayers mouse as the Parameter. You can just access all that you need before the event scopes.

local tool = script.Parent.Parent
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:wait()
local humanoid = character:WaitForChild("Humanoid")

tool.Equipped:Connect(function()
    humanoid.Health = 50
end)

tool.Unequipped:Connect(function()
    humanoid.Health = 100
end)
0
Exactly like I said above, equip is not a parameter of tool.Equiped. JudgeDuckie 5 — 11d
0
Judge Duckie you didn't really say that. But ok! N43FGXL 12 — 11d
0
Thank you so much Azarth! N43FGXL 12 — 11d
Ad
Log in to vote
0
Answered by 12 days ago

I don't think equip is a property in the parenthesis.

0
-So remove 'equip' JudgeDuckie 5 — 12d
0
Do you even know what a parameter is? I am using the "equip" parameter for the person who equipped the item. I'm not sure you know what parameters are.. N43FGXL 12 — 11d
0
I know they are called parameters just forgot, it was 9pm I was trying to help. JudgeDuckie 5 — 11d

Answer this question