Stamina Recovery/Regenaration Speed Up

Hello everyone, this is my first post in the dev forum! I am currently making a stamina system, test it out and it’s all good but then I noticed that :

Whenever a player jumps, the stamina increase faster than it’s supposed to.


I recorded the time. Without jumping, it takes 33 seconds for it to be full. Jumping however, it takes 5 seconds for the stamina bar to be full. That’s 28 seconds difference!


The Script [Local Script] :

-- \\\\\\\\\\\\\\\\\\\\ MAIN VARIABLES  ////////////////////

local UIS = game:GetService('UserInputService')
local SprintFrame = script.Parent:WaitForChild('Sprint')
local Bar = script.Parent:WaitForChild('Sprint'):WaitForChild('Bar')
local player = game.Players.LocalPlayer

-- \\\\\\\\\\\\\\\\\\\\ SPRINT VARIABLES ////////////////////

local NormalWalkSpeed = 16
local NewWalkSpeed = 30
local ii = 10
local running = false
repeat wait() until game.Players.LocalPlayer.Character
local character = player.Character

-- \\\\\\\\\\\\\\\\\\\\ DOUBLE JUMP VARIABLES  ////////////////////

local canDoubleJump = false
local hasDoubleJumped = false
local oldPower
local TIME_BETWEEN_JUMPS = 0.2
local DOUBLE_JUMP_POWER_MULTIPLIER = 1

-- \\\\\\\\\\\\\\\\\\\\ ANIMATION STUFF  ////////////////////

local Anim = Instance.new('Animation')
Anim.AnimationId = 'rbxassetid://10440816655'
PlayAnim = character.Humanoid:LoadAnimation(Anim)

-- \\\\\\\\\\\\\\\\\\\\ SPRINT  ////////////////////

UIS.InputBegan:connect(function(key, gameProcessed)
	    local hum = character:WaitForChild("Humanoid")
		if key.KeyCode == Enum.KeyCode.LeftShift and gameProcessed == false then
		character.Humanoid.WalkSpeed = NewWalkSpeed
		running = true
		PlayAnim:Play()
		while ii > 0 and running do
			--SprintFrame.Visible = true
			ii = ii - .03
			
			Bar:TweenSize(UDim2.new(ii / 10, 0, 1, 0), 'Out', 'Quint', .1, true)
			--Bar.BackgroundColor3 = Bar.BackgroundColor3:lerp(Color3.fromRGB(255, 42, 42), 0.001)
			wait()
			if ii <= 0 then
				character.Humanoid.WalkSpeed = NormalWalkSpeed
				PlayAnim:Stop()
			elseif character.Humanoid.MoveDirection.Magnitude == 0 then
				PlayAnim:Stop()
				character.Humanoid.WalkSpeed = NormalWalkSpeed
				running = false
			end
		end
	end
end)

UIS.InputEnded:connect(function(key, gameProcessed)
	if key.KeyCode == Enum.KeyCode.LeftShift and gameProcessed == false or character.Humanoid.MoveDirection.Magnitude == 0 then 
		character.Humanoid.WalkSpeed = NormalWalkSpeed
		running = false
		PlayAnim:Stop()
		while ii < 10 and not running do
			ii = ii + .01
			Bar:TweenSize(UDim2.new(ii / 10, 0, 1, 0), 'Out', 'Quint', .1, true)
			--SprintFrame.Visible = false
			--Bar.BackgroundColor3 = Bar.BackgroundColor3:lerp(Color3.fromRGB(255, 166, 11), 0.001)
			wait()
			if ii <= 0 then
				character.Humanoid.WalkSpeed = NormalWalkSpeed
			end
		end
	end
end)

-- \\\\\\\\\\\\\\\\\\\\ DOUBLE JUMP STUFF ////////////////////

function onJumpRequest()
	if not character or not humanoid or not character:IsDescendantOf(workspace) or
		humanoid:GetState() == Enum.HumanoidStateType.Dead then
		return
	end

	if canDoubleJump and not hasDoubleJumped then
		hasDoubleJumped = true
		humanoid.JumpPower = oldPower * DOUBLE_JUMP_POWER_MULTIPLIER
		humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
		while ii > 0 and hasDoubleJumped do
			ii = ii - .05
			Bar:TweenSize(UDim2.new(ii / 10, 0, 1, 0), 'Out', 'Quint', .1, true)
			wait()
			if ii <= 0 then
				canDoubleJump = false
			end
		end
	end
end

local function characterAdded(newCharacter)
	character = newCharacter
	humanoid = newCharacter:WaitForChild("Humanoid")
	hasDoubleJumped = false
	canDoubleJump = false
	oldPower = humanoid.JumpPower

	humanoid.StateChanged:connect(function(old, new)
		if new == Enum.HumanoidStateType.Landed then
			canDoubleJump = false
			hasDoubleJumped = false
			humanoid.JumpPower = oldPower
			while ii < 10 and not hasDoubleJumped do
				ii = ii + .01
				Bar:TweenSize(UDim2.new(ii / 10, 0, 1, 0), 'Out', 'Quint', .1, true)
				wait()
				if ii <= 0 then
					ii = ii + .01
					Bar:TweenSize(UDim2.new(ii / 10, 0, 1, 0), 'Out', 'Quint', .1, true)
				elseif running == true then return end
			end
		elseif new == Enum.HumanoidStateType.Freefall then
			wait(TIME_BETWEEN_JUMPS)
			canDoubleJump = true
		end
	end)
end

-- \\\\\\\\\\\\\\\\\\\\   ////////////////////

if player.Character then
	characterAdded(player.Character)
end

player.CharacterAdded:connect(characterAdded)
UIS.JumpRequest:connect(onJumpRequest)

[Had to put on an entire script in case someone asked for it, preparation 100%]

I tried removing the :


ii = ii + .01

Which of course, the bar won’t go up. So I tried remove 2 of it [In Sprint and the 1st in Double Jump].

the 2nd line in the Double Jump did 0 effect which I think is good. I tested 2 of the line that I removed and it starts to happen again. What did I go wrong?


(Apologize for the lengthy post and sorry if you don’t understand what’s the issue here, thank you for reading this btw)

1 Like

I am sorry that this reply is very late. It might be because on the tween service you are using “Out”, “Quint”. Try Linear, Out.

I am really sorry if you already figured out the problem.