Delay between jumps

Hello, the delay between jumps does not work, what’s the problem?
Output say nothing

My script

local Players = game:GetService(“Players”)
local LocalPlayer = Players.LocalPlayer

local function onCharacterAdded(character)
local humanoid = character:WaitForChild(“Humanoid”)

local canJump = true
local jumpCooldown = 2
local lastJumpTime = 0

humanoid.Changed:Connect(function(property)
	if property == "Jump" and canJump then
		local currentTime = tick()
		if currentTime - lastJumpTime >= jumpCooldown then
			canJump = false
			lastJumpTime = currentTime
			humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
			canJump = true
		end
	end
end)

end

if LocalPlayer then
LocalPlayer.CharacterAdded:Connect(onCharacterAdded)

if LocalPlayer.Character then
	onCharacterAdded(LocalPlayer.Character)

end
end

image

This also works to not allow the player to jump:

local function DelayPlayerJump(Player: Player)
	Player.Character.Humanoid.JumpPower = 0
	task.wait(0.5)
	Player.Character.Humanoid.JumpPower = 50
end
1 Like

Does this still play the animation?

I know the usual method is to set the humanoid’s jump property to false when they try to jump on cooldown.

Can you say more about this method?

Bro dosnt work, my script

local function DelayPlayerJump(Player: Player)
Player.Character.Humanoid.JumpPower = 0
task.wait(0.5)
Player.Character.Humanoid.JumpPower = 50
end

game.Players.PlayerAdded:Connect(function(Player: Player)
Player.CharacterAdded:Connect(function(Character: Model)
local Humanoid = Character:WaitForChild(“Humanoid”)
Humanoid.Jumping:Connect(function()
task.spawn(function()
DelayPlayerJump(Player)
end)
end)
end)
end)

local JUMP_COOLDOWN = 3

local Character = script.Parent
local Humanoid = Character:FindFirstChild(“Humanoid”) or Character:WaitForChild(“Humanoid”) – Our player’s humanoid

local canJump = true

local function onStateChanged (_, newState)
if (newState == Enum.HumanoidStateType.Jumping) then
canJump = false
Humanoid:SetStateEnabled(“Jumping”, false)
task.wait(JUMP_COOLDOWN)
canJump = true
Humanoid:SetStateEnabled(“Jumping”, true)
end
end

Humanoid.StateChanged:Connect(onStateChanged)

I found good script, thank you all for help