Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I force the stamina bar to go up even if holding shift still?

Asked by 2 years ago

Ok so, I have the script and everything works amazingly, but theres one big problem. When the stamina bar gets to 0 and you're still holding shift instead of it going back up and the FOV reverting back it stays down and you stay in the runnning fov but walking. I want the FOV to go back to normal and the players Stamina to go up even if they're holding shift. Here's the code

--//Varaiables\\--
local camera = game.Workspace.CurrentCamera
local TweeningService = game:GetService("TweenService")
local UIS = game:GetService("UserInputService")
local Bar = script.Parent:WaitForChild('Border'):WaitForChild("Bar")
local player = game.Players.LocalPlayer
local walk = 14
local run = 18
local power = 10
local sprinting = false
repeat wait() until game.Players.LocalPlayer.Character
local character = player.Character
local runService = game:GetService('RunService')

--//Tweens\\--
local FOVChanges = {
    FieldOfView = 90
}

local TweenInformation = TweenInfo.new(
    1,
    Enum.EasingStyle.Quint,
    Enum.EasingDirection.Out,
    0,
    false,
    0
)

local tween = TweeningService:Create(camera, TweenInformation, FOVChanges)

local FOVChanges2 = {
    FieldOfView = 70
}

local TweenInformation2 = TweenInfo.new(
    1,
    Enum.EasingStyle.Quint,
    Enum.EasingDirection.Out,
    0,
    false,
    0
)

local tween2 = TweeningService:Create(camera, TweenInformation2, FOVChanges2)

--//Shift Pressed and Let Go\\--
UIS.InputBegan:Connect(function(key, gameProcessed)
    if key.KeyCode == Enum.KeyCode.LeftShift and gameProcessed == false and character.Humanoid:GetState() == Enum.HumanoidStateType.RunningNoPhysics and character.Humanoid.MoveDirection.Magnitude > 0 then
        character.Humanoid.WalkSpeed = run
        sprinting = true
        while power > 0 and sprinting do
            power = power - .03
            Bar.Size = UDim2.new(power / 10, 0, 1, 0)
            tween:Play()
            wait()
            if power <= 0 then
                character.Humanoid.WalkSpeed = walk
                tween2:Play()
            end
        end
    end
end)

UIS.InputEnded:Connect(function(key, gameProcessed)
    if key.KeyCode == Enum.KeyCode.LeftShift and gameProcessed == false then
        character.Humanoid.WalkSpeed = walk
        sprinting = false
        while power < 10 and not sprinting do
            power = power + .03
            Bar.Size = UDim2.new(power / 10, 0, 1, 0)
            tween2:Play()
            wait()
            if power <= 0 then
                character.Humanoid.WalkSpeed = walk
            end
        end
    end
end)

Answer this question