i don’t think i have to explain video explains itself
--//Settings
local Maximum_Stamina = 100
local Stamina_Decrease = 0.4
local Stamina_Amount = Maximum_Stamina
local Sprint_Speed = 30
local Normal_Speed = 7
local Sprint_FOV = 100
local Normal_FOV = 70
--//Variables
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Current_Camera = workspace.CurrentCamera
--//Services
local Tween_Service = game:GetService("TweenService")
local Replicated_Storage = game:GetService("ReplicatedStorage")
local Run_Service = game:GetService("RunService")
local User_Input_Service = game:GetService("UserInputService")
--//Animations
local Sprint_Animation = script:WaitForChild("SprintAnimation")
local Play_Sprint_Animation = Humanoid:LoadAnimation(Sprint_Animation)
--//Gui
local Background = script.Parent.BackGround
local Bar = Background.Bar
--//Booleans
local IsSprinting = false
local function FOV_Tween(duration, FOV)
local tween = Tween_Service:Create(Current_Camera, TweenInfo.new(duration,Enum.EasingStyle.Quad), {FieldOfView = FOV})
tween:Play()
spawn(function()
tween.Completed:Wait()
tween:Destroy()
end)
end
--//Key Pressed Function
User_Input_Service.InputBegan:Connect(function(Input_Object, GameProcessed)
if Humanoid.MoveDirection.Magnitude > 0 then
if Input_Object.KeyCode == Enum.KeyCode.LeftShift and not GameProcessed then
if not IsSprinting then
IsSprinting = true
Humanoid.WalkSpeed = Sprint_Speed
FOV_Tween(0.8, Sprint_FOV)
if not Play_Sprint_Animation.IsPlaying then
Play_Sprint_Animation.Looped = true
Play_Sprint_Animation:Play()
end
end
end
else
if Play_Sprint_Animation.IsPlaying then
Play_Sprint_Animation:Stop()
Humanoid.WalkSpeed = Normal_Speed
end
end
end)
User_Input_Service.InputEnded:Connect(function(Input_Object)
if Input_Object.KeyCode == Enum.KeyCode.LeftShift then
IsSprinting = false
if Play_Sprint_Animation.IsPlaying then
Play_Sprint_Animation:Stop()
end
Humanoid.WalkSpeed = Normal_Speed
FOV_Tween(2, Normal_FOV)
end
end)
Run_Service.RenderStepped:Connect(function()
if Stamina_Amount > 0 then
if IsSprinting == true and Humanoid.MoveDirection.Magnitude > 0 then
Stamina_Amount =- Stamina_Decrease
end
end
if Stamina_Amount < Maximum_Stamina then
Background.Visible = true
local Formula = Stamina_Amount/Maximum_Stamina * 100
Bar:TweenSizeAndPosition(UDim2.new(1, 0, Formula, 0), UDim2.new(1, 0, 1 - Formula, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.1, true)
if not IsSprinting then
Stamina_Amount += Stamina_Decrease
end
else
Background.Visible = false
end
end)