I have made a tool that, when equipped, makes you walk faster, and then makes you walk slower after unequipping. The problem is that I get errors when I unequip the tool.
Backpack.Run.Script:10: attempt to index nil with 'WalkSpeed'
It seemed obvious at first; the tool was sent to the backpack after unequipping and therefore couldn’t check the humanoid from there, however, I had configured the script to save the humanoid in a variable but it still doesn’t work.
Here is the script:
local tool = script.Parent
local character
local humanoid
local debounce = true
function equipped()
if tool.Parent then
character = tool.Parent
humanoid = character:FindFirstChildOfClass("Humanoid")
humanoid.WalkSpeed = 32
end
end
function unequipped()
humanoid.WalkSpeed = 16
end
tool.Equipped:Connect(equipped)
tool.Unequipped:Connect(equipped)
I feel bad for bringing this up here since it sounds like a really simple issue, but I really don’t know how to fix this. I welcome any help on fixing this.