Hello, so I am attempting to create this stamina bar script. However, I have the sprinting part completed and tested. However, I want to incorporate the jumping power into the stamina bar. What I mean by this is that I want it when the player jumps it subtracts 10 from the stamina bar GUI. I'm afraid that when the player sprints it might screw up the stamina bar. I'm basically creating a limited sprint and jump script. Also the stamina bar glitches sometimes when I sprint as it goes out of the bar when regening my stamina.
Stamina Script:
local CAS = game:GetService("ContextActionService")
local RE = game:GetService("ReplicatedStorage"):WaitForChild("RE")
local fill = script.Parent:WaitForChild("top"):WaitForChild("fill")
local stam = 50
local speed = 16
local sprinting = false
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)
local function sprint(str, state, object)
if stam < 1 then return end
speed = state == Enum.UserInputState.Begin and 24 or 16
sprinting = state == Enum.UserInputState.Begin
while sprinting and stam > 0 and wait(.1) do
stam = stam - 1
fill:TweenSize(UDim2.new(stam/50, 0, 1, 0), "Out", "Sine", .1, true)
RE:FireServer('sprint', {speed})
end
sprinting = false
speed = 16
RE:FireServer('sprint', {speed})
wait(1)
while not sprinting and stam < 50 and wait(2) do
fill:TweenSize(UDim2.new(stam/50, 0, 1, 0), "Out", "Sine", .1, true)
stam = stam + 1
end
end
CAS:BindAction("sprint", sprint, true, Enum.KeyCode.LeftShift)
Please help me, thank you!

2 comments
The stamina bar still goes outside of the barrier. Also I don't know how I can add the jumping affect the stamina bar.
You use the humanoid.Jump event