Wanting to make a script in which after a function is called it will change the players Walkspeed Problem(You cant make it normal properly)

I wanted to make a script in which after you keep shovelling , using a tool, Your walkspeed will increase.
And after 6 seconds after you stop shovelling, your walkspeed will go back to normal.
What have i done:
I tried to make it so it waits after it increases the speed, then puts it back to normal.
But i found out that the function keeps on running even when its called again. Therefore the walkspeed goes back to normal even when im still shoveling.

First a function is called in a local script inside the starter pack.

showel = script.Parent
showelFunc= game.ReplicatedStorage.Shovelled
event = game.ReplicatedStorage.Snow
SnowBallName = "SnowPatchSCRIPTED"
local Debounce = true
showel.Equipped:Connect(function()
	local plr = game.Players.LocalPlayer
	local plrgui = game.Players.LocalPlayer.PlayerGui
	Txt = plrgui:WaitForChild("Popout").PopoutFrame.Amount
	local Character = plr.Character
	local Humanoid = Character:FindFirstChild("Humanoid")
	local mouse = plr:GetMouse()
	mouse.Button1Down:Connect(function()
		if Debounce then
			if mouse.Target.Name == SnowBallName and (mouse.Target.Position - showel.Handle.Position).Magnitude < 15 then
				
				event:FireServer(x, mouse.Target)
								
			end
		end

	end)
end)

The above script basically fires an event which increases the snowballs value.(Which is in leaderstats)
Then, a local script detects when the snowballs value is increased

plr = game.Players.LocalPlayer
Func = game.ReplicatedStorage.Shovelled
ldb = plr:WaitForChild("leaderstats")
Deb = true
snowballs = ldb:FindFirstChild("SnowBalls")
snowballs:GetPropertyChangedSignal("Value"):Connect(function()
	print("b")
	Deb = false
	local snb = snowballs.Value
	local B = 0.1
	local x = B + snb
	local character = plr.Character
	local humanoid = character:FindFirstChild("Humanoid")
	humanoid.WalkSpeed = x
	
	wait(10)
	local character = plr.Character
	local humanoid = character:FindFirstChild("Humanoid")
	humanoid.WalkSpeed = 16
end)

But as said above, it makes the speed normal even when the player is shovelling.
I would appretiate help.

Firstly, there’s a lot of things to do with your code, such as: Using local variables, already available references etc.

From this:

To this:

showel.Equipped:Connect(function(mouse)
	local plr = game.Players.LocalPlayer
	local plrgui = plr:WaitForChild("PlayerGui")
	local Amount = plrgui.PopoutFrame.Amount
	local Character = showel.Parent
	local Humanoid = Character:FindFirstChild("Humanoid")
	mouse.Button1Down:Connect(function()

Also, I don’t exactly know what’s the issue. Mind showing video of it?

Uhh so basically .
Every time the player clicks on a certain target,
An event is fired.
That event leads to the increase of snowballs.
After that another local script detects those snowballs changed and then increases the players speed accordingly. But, after 6 seconds of not shovelling, i want the walkspeed to go back to normal.
Do you know how to do that?
And i cant show a video. Theres nothing to show.

1 Like