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

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

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

✓ Accepted answer

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)

3 comments

0

Exactly like I said above, equip is not a parameter of tool.Equiped.

0

Judge Duckie you didn't really say that. But ok!

0

Thank you so much Azarth!

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

3 comments

0

-So remove 'equip'

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..

0

I know they are called parameters just forgot, it was 9pm I was trying to help.

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