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

Why is my speed tool not working when decreasing speed?

Asked by 4 years ago

This is the script and it works adding speed but breaks when decreasing

local tool = script.Parent
local Handle = tool:WaitForChild("Handle")

tool.Equipped:Connect(function()
    local h = script.Parent.Parent:FindFirstChild("Humanoid")
    h.WalkSpeed = h.WalkSpeed + 20  
end)

tool.Unequipped:Connect(function()
    local h = script.Parent.Parent:FindFirstChild("Humanoid")
    h.WalkSpeed = h.WalkSpeed - 20 --Here is the problem. It says that walkspeed is not a valid member of Humanoid
end)

1 answer

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

if script.Parent.Parent.Name == "Backpack" then
    character = script.Parent.Parent.Parent.Character
else
    character = script.Parent.Parent
end

h = character:WaitForChild("Humanoid")

tool.Equipped:Connect(function()
    h.WalkSpeed = h.WalkSpeed + 20
end)


tool.Unequipped:Connect(function()
    h.WalkSpeed = h.WalkSpeed - 20
end)
0
I believe it is losing the proper humanoid, as when you unequip it, it goes into the player's backpack, and it is looking for the humanoid in the player's backpack. LegoUnicornRoblox 37 — 4y
0
Yep works just fine. Tahnk You stranger HeroFigo 81 — 4y
Ad

Answer this question