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.
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.
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
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
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