How to make jump cooldown

ok so 1st you add a local script in StarterCharacterScripts
tu1

now open up the local script then put

local character = script.Parent

since the local script is in StarterCharacterScript you dont need to say

local character = plr.Character or plr.Character:Wait()

Same with StarterPlayer Script you dont need to say

local plr  = game.Players.LocalPlayer 
--or
local plrs = game:GetService("Players")
local plr =  plrs.LocalPlayer

anyways
you then add the character Humanoid by doing this

local hum = character = character:WaitForChild("Humanoid")
--or
local hum = character.Humanoid

So
Now that you make a variable for humanoid we can now get into the main area

add a variable like

local isJumping = false

you can name it anything

after you do that
you say

hum.StateChanged:Connect(function(landed) --you can change landed to anything

you might be thinking
“What is StateChanged and why did you add humanoid?”

well first of all i added the Humanoid Because you need the humanoid to get StateChanged and other stuff like walkSpeed

and the StateChanged is basically what state are you in
Are you in avatar state?
are you in idle state?

it basically something that is needed to make the rest of the things im gonna be explaining work.

ok Next

add in

if landed == Enum.HumanoidStateType.Landed then

if you are new to if then or elseif then i reccomend watch some ytuber tutorials
and read this

and when you use if then you need to add an
“end”
at the end of the script

Next is optional

Add this

		print("1")
		wait(0.3)
		print("2")
		wait(0.3)
		print("3")
		wait(0.3)
		wait(0.1)

basically how much more seconds you need to wait until you can jump again
as i said its optional

next
this is where the magic comes in

continuing from the

if landed == Enum.HumanoidStateType.Landed then

add in this

isJumping = true
hum:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)

remember when i said isJumping = false?
well now we say isJumping = true because after we waited 3 seconds after we landed so now we can now jump

in order for the script to work properly add an
else statement

by doing this

else

add it right below the

	isJumping = true
		hum:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)

after you added the else
you do the opposite because
its like
i drank water
i can now eat a fruit
but if i already ate a fruit
i will drink water
so the whole script will be like this


local character = script.Parent
local hum = character.Humanoid


local isJumping = true
hum.StateChanged:Connect(function(landed)

	if landed == Enum.HumanoidStateType.Landed then
		
		
		print("1")
		wait(0.3)
		print("2")
		wait(0.3)
		print("3")
		wait(0.3)
		wait(0.1)
		isJumping = true
		hum:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)
	else
		isJumping = false
		hum:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
	end

	
end)

also i forgot to explain why i added the end)
i added the end) because i had a function in

hum.StateChanged:Connect(function(landed)

this is my 1st ever tutorial im bad at teaching
if u ever see a mistake tell me

heres a video of me using it

20 Likes

Good. Straight to the point and seems cool.

Not sure how this would be useful, as it annoys me when you can’t jump constantly, however, it’s good tutorial for what it is.

3 Likes

thank u thought someone was gonna be writing a whole paragraph on how bad this was

2 Likes

No. It’s quite good.

It works and does the job.

1 Like
local character = script.Parent
local hum = character.Humanoid


local isJumping = true
hum.StateChanged:Connect(function(landed)

	if landed == Enum.HumanoidStateType.Landed then
		
		
		task.wait(1)
		isJumping = true
		hum:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)
	else
		isJumping = false
		hum:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
	end

	
end)

Not really much to add besides using task.wait() instead of wait() several times. Great job!

6 Likes

Good job on your explanations.
Many tutorials I’ve seen say ‘insert this script’ or something similar, but you explain why each item is added or not needed.

1 Like

well done, but u can also just use debounce :moyai:

1 Like

i forgor :skull:

1 Like

Playing the devil’s advocate, that was not a whole paragraph. Not even close. But it does have many uses! In PvP and Shooter games off the top of my head!

1 Like

Okay but you should switch to task.wait and you should also tell me why you added multiple waits

2 Likes

30 max characters at it’s finest

1 Like

what task.wait do?
also i woudlve made it with a gui i only do that for example

1 Like

It serves the same purpose as wait, but more accurate

It’s good practice to switch to the task.wait because wait is soon going to get deprecated.

1 Like

ik this was two years ago but pretty sure you can just use this

local Humanoid:Humanoid = script.Parent.Humanoid -- put the script in starter character scripts
local Delay = 1.5 -- change the delay as you like, i found that 1.5 is the best if the gravity of your experience is default

Humanoid.Jumping:Connect(function(jumped)
	if jumped then
		Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
		wait(Delay)
		Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)
	end
end)
1 Like

I’ve done this but sometimes after a while without respawning this script breaks for some reason