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

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

Asked by
N43FGXL 169
4 years 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 3141 Moderation Voter Community Moderator
4 years ago
Edited 4 years 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 25 — 4y
0
Judge Duckie you didn't really say that. But ok! N43FGXL 169 — 4y
0
Thank you so much Azarth! N43FGXL 169 — 4y
Ad
Log in to vote
1
Answered by 4 years ago

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

0
-So remove 'equip' JudgeDuckie 25 — 4y
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 169 — 4y
0
I know they are called parameters just forgot, it was 9pm I was trying to help. JudgeDuckie 25 — 4y

Answer this question