Hello I’m working on a jump script. When you jump 3 times it’ll give the character a cooldown to jump again. I’ve succeeded on this part but I can’t figure out how to make it so if the Player jumps once or twice and doesn’t jump again after a while that the count will go back to 0. So if the player doesn’t jump for say 8 seconds then the count will go back to 3. This is my script:
local Player = game.Players.LocalPlayer
local Humanoid = Player.Character:FindFirstChild(“Humanoid”)
jumps = 0
maxjumps = 3
Humanoid.Jumping:Connect(function(IsJumping)
if jumps == maxjumps then
Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping,false)
task.wait(3)
jumps = 0
Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping,true)
if not IsJumping or jumps == 1 or jumps == 2 and task.wait(8) then
jumps = 0
end
else
if IsJumping then
jumps = jumps + 1
end
end
probably use runservice and set on the priority list 2000 is ran after character, so something like Runservice:BindToRenderSteppee("disable jumping",2000,function,()humanoid.jumping=false end)
How about setting a variable outside the jumping function in the script called something like lastJumpTime, and every time the player jumps, set the lastJumpTime = tick() or Os.Time() etc. Whenever a player jumps, check the lastJumpTime and if it’s been 8 seconds or more, set jumps back to 0.
local MAX_JUMPS = 3 -- How many jumps until cooldown
local JUMP_COOLDOWN = 3 -- How many seconds the cooldown lasts
local JUMP_REST_TIME = 8 -- How many seconds of not jumping for jumps to be restored
local player = game:GetService("Players").LocalPlayer
-- Wait for humanoid to load
local humanoid = player.Character:WaitForChild("Humanoid")
local jumps = 0
local function jumpRestore()
while true do
task.wait(JUMP_REST_TIME)
jumps = 0
end
end
local jumpRestoreThread = nil
humanoid.Jumping:Connect(function(isJumping) -- When we jump
if jumps >= MAX_JUMPS then -- If we have exceeded the limit
humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false) -- Disable jumping
task.wait(JUMP_COOLDOWN) -- Wait until cooldown finishes
jumps = 0 -- Reset counter
humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true) -- Enabled jumping
elseif isJumping then -- We are jumping
jumps += 1 -- Add to count
if jumpRestoreThread then task.cancel(jumpRestoreThread) end -- Cancel the jump restore
jumpRestoreThread = task.spawn(jumpRestore) -- Start restore function
end
end)
Thank you man I’ve been getting into scripting recently and I will now review this code over and over and keep expanding to my knowledge. And for anyone else reading here’s a nice jump cooldown code!