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

Decreasing speed when unequipping a tool doesn't work?

Asked by 4 years ago

Ok so this tool functions like a speed coil (kinda) and I need the speed to be back to normal when the player unequips it but it's not working for some reason? Giving me an error which says:

"UnEquipped is not a valid member of Tool"

local tool = script.Parent.Parent

tool.Equipped:Connect(function() --Will listen for when the player equips the tool then connects to the enclosed function
    local char = tool.Parent --When a tool is equipped it moves from the backpack to the character model
    char.Humanoid.WalkSpeed = 14 --Sets the walkspeed by finding the humanoid that's under the character
end)

tool.UnEquipped:Connect(function() --Will listen for when the player equips the tool then connects to the enclosed function
    local char = tool.Parent --When a tool is equipped it moves from the backpack to the character model
    char.Humanoid.WalkSpeed = 12 --Sets the walkspeed by finding the humanoid that's under the character
end)

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago
local tool = script.Parent

tool.Equipped:Connect(function()
    tool.Parent.Humanoid.WalkSpeed = 14 --when equip tool tool parent is character
end)

tool.Unequipped:Connect(function() 
    tool.Backpack.Parent.Character.Humanoid.WalkSpeed = 12 --When you unequip tool your parent is backpack so parent backpack is player 
end)

0
I had to edit your script a bit but it works, thank you kind lad Simpletton 82 — 4y
Ad

Answer this question