I need a way to make a cooldown for my movement system's long-jump

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

Trying to achieve a cooldown for my longJump

  1. What is the issue? Include screenshots / videos if possible!

There is no cooldown so it just lets me constantly loop

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

Debounces, etc.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

function moveSet:longJump()
	if not (self.isLongJumpActive and self._canLongJump and self:isAlive() and not self:inAir()) then
		return false;
	end

	self._isLongJumping = true;
	self._canLongJump = false;

	self.humanoid.JumpPower = 0;
	self.humanoid:ChangeState(Enum.HumanoidStateType.Jumping); -- unless the character is jumping we can't set its velocity

	local hrpCF = self.hrp.CFrame;
	local ray = Ray.new(hrpCF.p, -5*hrpCF.upVector);
	local hit, pos, normal = game.Workspace:FindPartOnRay(ray, self.character);
	normal = normal:Dot(normal) > 0 and normal or UP;

	self.hrp.Velocity = self.longJumpSpeed*(normal:Cross(hrpCF.lookVector):Cross(normal)).unit + self.longJumpPower*normal;

	self.currentAnim:Stop();
	self.currentAnim = self.longJumpAnim;
	self.currentAnim:Play(0.2, nil, 1);

	--long jump man

	return true;
end
1 Like

The simplest way is to use tick() to get the current time and record when the last jump happened. That way, at some later point you can calculate the time since that event happened by subtracting it from the new, higher value of tick(). If the time that has passed is great enough, the cooldown is done.

function secondsSince(time)
    return tick() - time
end

function moveSet:isLongJumpCooldownDone()
    if not self._lastLongJumpTime then return true end
    return secondsSince(self._lastLongJumpTime) >= LONG_JUMP_COOLDOWN
end

function moveSet:longJump()
    if not (... and self:isLongJumpCooldownDone()) then return false end
    ...
    self._lastLongJumpTime = tick()
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.