local Player = game.Players.LocalPlayer
local Character = Player.Character
local UserInputService = game:GetService("UserInputService")
local Stamina = 250
local isRunning = false
Stamina = math.clamp(Stamina, 0, 250)
UserInputService.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
isRunning = true
Character.Humanoid.WalkSpeed = 28
while Stamina > 0 and isRunning do
Stamina = Stamina - 1
script.Parent:TweenSize(UDim2.new(Stamina / 250, 0, 1, 0), "Out", "Linear", 0)
task.wait()
if Stamina <= 0 then
Character.Humanoid.WalkSpeed = 16
end
end
end
end)
UserInputService.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
isRunning = false
Character.Humanoid.WalkSpeed = 16
while Stamina < 250 and not isRunning do
Stamina = Stamina + 0.5
script.Parent:TweenSize(UDim2.new(Stamina / 250, 0, 1, 0), "Out", "Linear",0)
task.wait()
if Stamina == 0 then
Character.Humanoid.WalkSpeed = 16
end
end
end
end)
Hierarchy:
If you think you know what went wrong, please let me know. Thank you and have a wonderful day!
Change the Hierarchy so that the Bar is inside the background. I am assuming that Background is the background of the stamina bar. Currently you are setting the stamina bar to take up the full screen instead of the full background.
script.Parent.Rotation += 180
local Player = game.Players.LocalPlayer
local Character = Player.Character
local UserInputService = game:GetService("UserInputService")
local Stamina = 250
local isRunning = false
Stamina = math.clamp(Stamina, 0, 250)
UserInputService.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
isRunning = true
Character.Humanoid.WalkSpeed = 28
while Stamina > 0 and isRunning do
Stamina = Stamina - 1
script.Parent:TweenSize(UDim2.new(1, 0, Stamina / 250, 0), "Out", "Linear", 0)
task.wait()
if Stamina <= 0 then
Character.Humanoid.WalkSpeed = 16
end
end
end
end)
UserInputService.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
isRunning = false
Character.Humanoid.WalkSpeed = 16
while Stamina < 250 and not isRunning do
Stamina = Stamina + 0.5
script.Parent:TweenSize(UDim2.new(1, 0, Stamina / 250, 0), "Out", "Linear",0)
task.wait()
if Stamina == 0 then
Character.Humanoid.WalkSpeed = 16
end
end
end
end)