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

Player walkspeed resets to normal when i click?

So ive made a hammer that does a lot of damage to a humanoid, and then i made a script that slows down the player when you equip the hammer.

local Tool = script.Parent
local plr = game:GetService('Players').LocalPlayer
local Enabled = false

Tool.Activated:Connect(function()
	if not Enabled then
		Enabled = true
		plr.Character.Humanoid.WalkSpeed = 3
	else
		Enabled = false
		plr.Character.Humanoid.WalkSpeed = 16
	end
end)

But then whenever i clicked the walkspeed resets to normal! I thought it might be the damage script so i put that in server storage to see if it worked after that, and even without the damage scripts the walkspeed resets to normal when you click the mouse! It also turns it back to 3 when you click again. Could anyone point out a problem as this is completely beyond me lol.

1 answer

✓ Accepted answer

That's because the script just toggles the walkspeed when walking.


local Tool = script.Parent
local plr = game:GetService('Players').LocalPlayer
local deb = false
local cooldown = 0.5 -- how long you walk slower in seconds you can set it to anything you want for example 1 to 1 second

Tool.Activated:Connect(function() -- fires on activated
	if deb then return end -- stop when debounce is active
	deb = true 
	plr.Character.Humanoid.WalkSpeed = 3
	wait(cooldown)
	plr.Character.Humanoid.WalkSpeed = 16
    deb = false
end)

1 comment

1

Thanks!

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