I made this Sprinting System, but when the player jumps several times he recovers his stamina very quickly, running the loop several times, what i can do?
UserInputService.InputBegan:Connect(function(input) -- JUMP in
if input.KeyCode == Enum.KeyCode.Space and CanRun.Value == true and stamina >=0.3 then
Character.Humanoid.JumpHeight = 5
v:TweenSize(UDim2.new(stamina/100, 0, 1, 0), 'Out', 'Linear', 0)
wait()
if stamina <= 30 then
TweenService:Create(RespirandoSound,TweenInfo.new(0.5,Enum.EasingStyle.Linear,Enum.EasingDirection.In),{Volume = 0.5}):Play()
elseif stamina >30 then
TweenService:Create(RespirandoSound,TweenInfo.new(0.5,Enum.EasingStyle.Linear,Enum.EasingDirection.In),{Volume = 0}):Play()
end
if stamina <=1 then
Character.Humanoid.WalkSpeed = 10
Character.Humanoid.JumpHeight = 0
Fadiga = true
delay(7,function()
Fadiga = false
end)
end
stamina -= 2
end
end)
UserInputService.InputEnded:Connect(function(input) -- JUMP out
if input.KeyCode == Enum.KeyCode.Space then
if CanRun.Value == true then
Character.Humanoid.WalkSpeed = StarterPlayer.CharacterWalkSpeed
Character.Humanoid.JumpHeight = StarterPlayer.CharacterJumpHeight
end
while stamina < 100 and Sprinting == false do
v:TweenSize(UDim2.new(stamina/100, 0, 1, 0), 'Out', 'Linear', 0)
wait()
if stamina >30 then
TweenService:Create(RespirandoSound,TweenInfo.new(0.5,Enum.EasingStyle.Linear,Enum.EasingDirection.In),{Volume = 0}):Play()
end
if Fadiga == false then
stamina += 0.1
elseif Fadiga == true then
Character.Humanoid.WalkSpeed = 10
Character.Humanoid.JumpHeight = 0
end
end
end
end)