Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why is my speed tool not working when decreasing speed?

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

✓ Accepted answer
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)

2 comments

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.

0

Yep works just fine. Tahnk You stranger

This discussion is preserved as it was. New answers, comments, and votes are closed.