[HELP] My jump cooldown script isn't working

Hello, I’ve been trying to make a little script so there would be a jump cooldown. I wanted the cooldown to be 5, so that when a player jumps, they won’t be able to jump for the next 5 seconds.

repeat wait() until game.Players.LocalPlayer.Character

local Jumped = false
local Player = game.Players.LocalPlayer
local Char = Player.Character
local UIS = game:GetService('UserInputService')

Char:FindFirstChild('Humanoid').JumpPower = 0


UIS.InputBegan:connect(function(input)
	if input.KeyCode == Enum.KeyCode.Space and not Jumped then
		Jumped = true
		Char:FindFirstChild('Humanoid').JumpPower = 50
		wait(.2)
		Char:FindFirstChild('Humanoid').JumpPower = 0
		wait(5)
		Jumped = false
	end
end)

Does anyone know what I did wrong in the script? Thanks in advance.

3 Likes

Are you executing it as local script?

Yes. (30 Characters) (30 Characters)

Instead of “starting with zero jump-power”, you may want to make your code work in “reverse”.

That is; allow the player to jump. - But as soon as the player has jumped, then set jump-power to zero and start the 5 seconds cooldown:

-- Char:FindFirstChild('Humanoid').JumpPower = 0

UIS.InputBegan:connect(function(input)
	if input.KeyCode == Enum.KeyCode.Space and not Jumped then
		Jumped = true
		wait() -- Maybe this `wait` is needed. Maybe not?
		Char:FindFirstChild('Humanoid').JumpPower = 0
		wait(5)
		Char:FindFirstChild('Humanoid').JumpPower = 50
		Jumped = false
	end
end)

Is there any important reason you are using UserInputService to tell if the player is jumping since there are much easier ways than this.

1 Like

I tried to put this into the script, but it didn’t work.

Could you please give me the easier ways? I’m new to scripting. :confused:

I would try and figure out a way to use the Humanoid.Jumping event and connect it to a function.

1 Like

Perhaps UserInputService.JumpRequest can be used, as on that documentation page, it explicitly has a code sample for ‘disable jumping’.

1 Like

Good find indeed. Will need slight reworking.

I’ve got honestly no idea where to find the code. I’m fairly new to scripting and I have no idea of what to do, do you know how to fix this?

The better way to do this is to store the time when the player jumped, and when the player requests to jump again, compare the current time to the last stored time. If the time difference is greater than 5 seconds they can jump again, then store the time.

1 Like

I understand what you’re saying, but how do I translate that into a proper working code?

You should spend some time (days, weeks) to read through the “Learn Roblox” articles, and possibly the “Gameplay” category.

In there I found a ‘Double Jumping’ article, which could give you some clues, on how to modify your code to do what you want it to do.

You don’t.

This is not where you can get free code, imo outlines are more than enough.


@delvuur

That aside, demonstration of what the above reply probably means to do,

Store the time when the player jumped as a variable possibly as var = tick(), when a player jumps again , subtract var from tick() to get the time elapsed, if greater than 5 then just let them jump, override the previous var. as the new time.


@luketeam5 @905lua
again, dumping scripts here with no explanation is completely useless to the OP

You can do it like this:

local cooldown = 5
local lastUsed = 0
local function jump()
       lastUsed = tick()
end
local function checkJump()
       return tick()-lastUsed >= cooldown
end



if checkJump() then
       jump()
       -- put your jump code here
end
1 Like

Give me while almost have it :slight_smile:

I know placing scripts here wont work, but I don’t really want to learn how to script. I want to give the game a few easy scripts so I can hire a professional scripter later-on when the build is done.

local character = game.Players.LocalPlayer.Character

local player = game.Players.LocalPlayer

local humanoid = character:WaitForChild("Humanoid")

local debounce = false -- We dont want to trigger code while falling

humanoid.Jumping:Connect(function(isActive)

if debounce == false then

debounce = true

wait(.2)

character.Humanoid.JumpPower = 0 -- Disabled jump

wait(5)

debounce = false

character.Humanoid.JumpPower = 50 -- Sets back to default

end

end)

Put it into StarterPlayer.StarterCharacterScripts

If you want version where it sets back to old one (before changing to 0) tell me :slight_smile:

5 Likes

Thank you for sending me this, but unfortunately it didn’t work. Do you have any idea why it didn’t?