How do I incorporate Jumping stamina in script

local UIS = game:GetService("UserInputService")
local TS = game:GetService("TweenService")
local plr = game.Players.LocalPlayer

local maxStamina = 360
local stamina = plr.Character:WaitForChild("Stamina")
stamina.Value = maxStamina
local isSprinting = false
local sprintCooldown = false
local sprintCooldownDuration = 3.5

-- Function to handle sprinting
local function startSprinting()
	isSprinting = true
	TS:Create(workspace.CurrentCamera, TweenInfo.new(0.75), { FieldOfView = 75 }):Play()
	TS:Create(plr.Character.Humanoid, TweenInfo.new(0.75), { WalkSpeed = 24 }):Play()
	TS:Create(plr.Character.HumanoidRootPart.Running, TweenInfo.new(0.75), { PlaybackSpeed = 3.7 }):Play()
end

-- Function to handle not sprinting
local function stopSprinting()
	isSprinting = false
	TS:Create(workspace.CurrentCamera, TweenInfo.new(0.75), { FieldOfView = 45 }):Play()
	TS:Create(plr.Character.Humanoid, TweenInfo.new(0.75), { WalkSpeed = 16 }):Play()
	TS:Create(plr.Character.HumanoidRootPart.Running, TweenInfo.new(0.75), { PlaybackSpeed = 1.85 }):Play()
end

local function handleStamina()
	if isSprinting then
		if stamina.Value >= 1 then
			stamina.Value = math.max(0, stamina.Value - 1)
		else
			stopSprinting()
			sprintCooldown = true
			plr.Character.Humanoid.JumpPower = 0
			wait(sprintCooldownDuration)
			sprintCooldown = false
			plr.Character.Humanoid.JumpPower = 45
		end
	elseif not isSprinting and stamina.Value < maxStamina then
		stamina.Value = stamina.Value + 0.5
	end
end

game:GetService("RunService").RenderStepped:Connect(handleStamina)

UIS.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.LeftShift or input.KeyCode == Enum.KeyCode.RightShift then
			if stamina.Value > 0 and not sprintCooldown then
				startSprinting() 
			end
		end
	end
end)

UIS.InputEnded:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.LeftShift or input.KeyCode == Enum.KeyCode.RightShift then
			if not sprintCooldown then
				stopSprinting()
			end
		end
	end
end)

I do not know where to begin, I am dumbfounded on how to make it so that jumping subtracts stamina, making it so you cant jump untils sprintcooldown is finished, and make it compatible with the sprinting that also takes stamina.

You can get the humanoid state for jumping and connect a function to it to subtract stamina.

Maybe have it so the stamina also takes away or adds to the jump power.
If you have stamina script going, be a simple add and more realistic.

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