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 5 years ago

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

01local tool = script.Parent
02local Handle = tool:WaitForChild("Handle")
03 
04tool.Equipped:Connect(function()
05    local h = script.Parent.Parent:FindFirstChild("Humanoid")
06    h.WalkSpeed = h.WalkSpeed + 20 
07end)
08 
09tool.Unequipped:Connect(function()
10    local h = script.Parent.Parent:FindFirstChild("Humanoid")
11    h.WalkSpeed = h.WalkSpeed - 20 --Here is the problem. It says that walkspeed is not a valid member of Humanoid
12end)

1 answer

Log in to vote
2
Answered by 5 years ago
01local tool = script.Parent
02 
03if script.Parent.Parent.Name == "Backpack" then
04    character = script.Parent.Parent.Parent.Character
05else
06    character = script.Parent.Parent
07end
08 
09h = character:WaitForChild("Humanoid")
10 
11tool.Equipped:Connect(function()
12    h.WalkSpeed = h.WalkSpeed + 20
13end)
14 
15 
16tool.Unequipped:Connect(function()
17    h.WalkSpeed = h.WalkSpeed - 20
18end)
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 — 5y
0
Yep works just fine. Tahnk You stranger HeroFigo 81 — 5y
Ad

Answer this question