Help with implementing a sprint cooldown

  1. What do you want to achieve?
    Create a cooldown for sprinting so that players cant spam the button

  2. What is the issue?
    Using debounce, the cooldown would work for the first 30 seconds or less sometimes of testing but then would reverse to no cooldown at all.

  3. What solutions have you tried so far?
    I’ve tried using debounce to make the cooldown and have tried moving it around trying to get it right but I honestly don’t really know what I’m doing with it. There also seems to be no tutorials that help my specific situation.

Main part of the Sprint Script:

	if UIS:IsKeyDown(Enum.KeyCode.LeftShift) and gameProcessed == false and UIS:IsKeyDown(Enum.KeyCode.W) then
		if debounce == true then 
		 end
			character.Humanoid.WalkSpeed = NewWalkSpeed
			sprinting = true
			PlayAnim:Play()
		if sprinting == true then 
			debounce = true 
		end
		while power > 0 and sprinting do
			power = power - .03
			Bar.Size = UDim2.new(power / 10, 0, 1, 0)
			tween:Play()
			wait()
			if power <= 0 then
				character.Humanoid.WalkSpeed = NormalWalkSpeed
				PlayAnim:Stop()
				tween2:Play()
				end
			end
		end
	end)

UIS.InputEnded:connect(function(key, gameProcessed)
	if not UIS:IsKeyDown(Enum.KeyCode.LeftShift) and gameProcessed == false or not UIS:IsKeyDown(Enum.KeyCode.W) or power <= 0 then 
		character.Humanoid.WalkSpeed = NormalWalkSpeed
		PlayAnim:Stop()
		sprinting = false
		tween2:Play()
		if sprinting == false then 
			delay(5,function()
			debounce = false
			while power < 10 and not sprinting do
				power = power + .03
				Bar.Size = UDim2.new(power / 10, 0, 1, 0)
				wait()
				tween2:Play()
				end 
			end)
		end
	end
end)

Also this isnt my own script, I just got it from the toolbox and modified it to what I needed it to do plus I’ve only been scripting for maybe a month so please explain to me like im a chimp :slight_smile: