Also, how do i make it so it cannot be triggered again while it's active? (btw, this is a local script from StarterGui)
Cooldown = 10 repeat wait() until script.Parent.Parent.Character Character = script.Parent.Parent.Character local Human = Character:WaitForChild("Humanoid") local LastJump = time() Human.Changed:connect(function(Prop) if Prop and Prop == "Jump" and Human.Jump then local CurrentTime = time() if LastJump + Cooldown > CurrentTime then Human.Jump = false for i = 10, 0, -1 do script.Parent.JumpCD.TextLabel.Text = "Jump Cooldown: " ..i wait(1) end else LastJump = CurrentTime end end end)
Instead of using a Changed
event on the Humanoid
, use the Jumping
event. We can also disable the Humanoid
from jumping internally using SetStateEnabled
.
This code snippet below should work, but if it doesn't please let me know. I've added a few conditions: do not start cooldown if the player cannot jump in the first place, and to stop changing the TextLabel
when the player died. I disable the humanoid from jumping until it requests the jump.
local PlayerService = game:GetService("Players") local Heartbeat = game:GetService("RunService").Heartbeat --Player objects. local Player = PlayerService.LocalPlayer local Character = Player.Character or Player.CharacterAdded:Wait() local Humanoid = Character:WaitForChild("Humanoid") --Configurations. local Cooldown = 3 local Debounce = false --Other objects. local TextLabel = script.Parent local function JumpWithCooldown() --Check if the player is not on air. if not Debounce then Debounce = true Humanoid.Jump = true Heartbeat:Wait() --Disables the humanoid from jumping. Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false) for i = Cooldown, 0, -1 do --We want this to stop printing when the humanoid dies. if Humanoid:GetState() == Enum.HumanoidStateType.Dead then TextLabel.Text = "You died. " .. i break end TextLabel.Text = "Jump cooldown: " .. i wait(1) end --Reenable jumping. Debounce = false Heartbeat:Wait() Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true) end end Humanoid.Jumping:Connect(JumpWithCooldown)