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

How do I add a Cooldown that prevents the player from mashing the Shift key?

I have a script that lets the player Sprint when Shift is pressed. The script is below. I wan't to make it so that everytime the Shift key is released theres a 3 second cooldown for when the Player can press Shift to Sprint again.

script.Parent:FindFirstChild("Ok").Parent.Text = "Sprint: "..script.Sprinting.Value

game:GetService("UserInputService").InputBegan:connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftShift then
		script.Deduct.Value = true
		while script.Deduct.Value == true and script.Sprinting.Value > 0 == true do
	    script.Sprinting.Value = script.Sprinting.Value - 1
	    print(script.Sprinting.Value)
		script.Parent.Text = "Sprint: "..script.Sprinting.Value
		game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 25	
		wait(0.2)	
		end	
    
    end
end)

 game:GetService("UserInputService").InputEnded:connect(function(input)
		if input.KeyCode ~= Enum.KeyCode.LeftShift then
		       print()
	else
		script.Deduct.Value = false
		game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16	
	end
	
end)

2 comments

0

Sorry I got to you so late, I;ll ad you on discord if you need further help

0

Feel free to add me, i'll message you if any more issues come up. My discord is same dude#1436.

1 answer

✓ Accepted answer

Have a seperate script that detects when the player releases LeftShift and then use that script to do something like

PlayerGui.SprintScript.Disabled = true
wait(3)
PlayerGui.SprintScript.Disabled = false

change playergui to wherever the script is being stored, and change SprintScript to whatever it's called.

2 comments

0

If you want, I can help with the place

0

Add me on discord if you're interested. My discord is same dude#1436.

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