function OnUnequip() script.Parent.Parent.Humanoid.WalkSpeed = 16 end
script.Parent.Unequipped:connect(OnUnequip)
I'm making a tool that when you equip it your walkspeed is set to 100
what I'm having trouble with is when you unequip it the walkspeed doesnt change back to 16
whats wrong with this script? I think it's because the tool is no longer the players child so it cant set the walkspeed to 16, but I don't know how to fix this
I'm a beginner scripter in need of help
When you unequip the tool, it will be placed back into your Backpack
. This is why 'script.Parent.Parent' will never have a Humanoid in it.
You have to reference the Character object, then reference the Humanoid.
function OnUnequip() local plr = script.Parent.Parent.Parent --script,tool,backpack,player local hum = plr.Character.Humanoid; hum.WalkSpeed = 16; end script.Parent.Unequipped:connect(OnUnequip)
Also, you could just use a LocalScript.
local players = game:GetService('Players') local me = players.LocalPlayer repeat wait() until me.Character local char = me.Character local humanoid = char:WaitForChild("Humanoid") local tool = script.Parent -- If you aren't using a handle, make sure you untick the option in the tools properties local minimum_walkspeed = 16 local max_walkspeed = 100 local function setWalkspeed(walkspeed) humanoid.WalkSpeed = walkspeed end tool.Equipped:connect(function() setWalkspeed(max_walkspeed) end) tool.Unequipped:connect(function() setWalkspeed(minimum_walkspeed) end)