Basically im working on a stamina bar but it doesnt work xd
local UserInputService = game:GetService("UserInputService")
local SPRINT_SPEED = 32
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
repeat wait() until player.Character
local char = player.Character
local hum = player.Character:WaitForChild("Humanoid")
local gui = script.Parent
local fill = gui.EnergyBar.Fill
local sprinting = false
local stamina = Instance.new("StringValue",player)
stamina.Name = "stamina"
stamina.Value = 100
local canSprint = true
UserInputService.InputBegan:connect(function(key, gameProcessedEvent)
if not gameProcessedEvent and key.KeyCode == Enum.KeyCode.LeftShift and hum and not sprinting and canSprint then
sprinting = true
hum.WalkSpeed = SPRINT_SPEED
while stamina.Value > 0 do
fill:TweenSize(UDim2.new(stamina.Value * 0.01, 0, 1, 0), "Out", "Quad", 0.5)
stamina.Value = stamina.Value - 1
wait(0.5)
end
if hum then
hum.WalkSpeed = 16
end
sprinting = false
end
end)
UserInputService.InputEnded:connect(function(key, gameProcessedEvent)
if not gameProcessedEvent and key.KeyCode == Enum.KeyCode.LeftShift and hum then
sprinting = false
end
end)
while true do
if stamina.Value < 100 then
stamina.Value = stamina.Value + 1
fill:TweenSize(UDim2.new(stamina.Value * 0.01, 0, 1, 0), "Out", "Quad", 0.5)
end
if stamina.Value >= 33 then
canSprint = true
elseif stamina.Value == 0 then
canSprint = false
end
wait(0.5)
end