So I scripted a tool that should make the player sprint once it is selected, and return the walkspeed back to normal once it is deselected. The player does sprint once they select the tool, but the problem is that when the player deselects the tool, the walkspeed doesn't return back to normal, and the sprinting continues... and I'm clueless as to why the deselect function isn't working. Any help would be appreciated. Thanks! (The script is below)
function onSelected(onSelected) script.Parent.Parent.Parent.Character.Humanoid.WalkSpeed = 100 end function onDeselected(onDeselected) script.Parent.Parent.Parent.Character.Humanoid.WalkSpeed = 16 end script.Parent.Selected:connect(onSelected) script.Parent.Deselected:connect(onDeselected)
I'm not sure but maybe you spelt something wrong or deselected isn't the right function.
Instead of Selected and Deselected, use Equipped and Unequipped.
local Tool = script.Parent local Players = game:GetService('Players') local Player = nil -- will obviously change upon equip Tool.Equipped:Connect(function() Player = Players:GetPlayerFromCharacter(Tool.Parent) if Player.Character and Player.Character:FindFirstChild('Humanoid') then Player.Character.Humanoid.WalkSpeed = 100 end end) Tool.Unequipped:Connect(function() -- added player check here incase the slight off chance it didn't find player if Player and Player.Character and Player.Character:FindFirstChild('Humanoid') then Player.Character.Humanoid.WalkSpeed = 16 end end)