I've made an FE compatible sprinting GUI that depletes when the user holds LeftShift. When the sprinting RE is fired to the server, the player's speed is changed to 24 when sprinting, and back to 16 otherwise.
Now, there are two problems that I'm having here with this script:
For some reason the bar depletes faster in-game rather than in test mode. I've come up with a work around by increasing the time it takes to deplete, but I'm still not sure why this happens.
The stamina bar always moves up to 101 stamina rather than the preferred 100 even when I've made checks to see if the bar should replete only when currentStamina < maxStamina. Note that this occurs both in-game and in test mode.
CLIENT:
local players = game:GetService('Players')
local replicatedStorage = game:GetService('ReplicatedStorage')
local userInputService = game:GetService('UserInputService')
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:wait()
local humanoid = character:WaitForChild('Humanoid')
local playerGui = player:WaitForChild('PlayerGui')
local gui = playerGui:WaitForChild('GUI')
local events = replicatedStorage:WaitForChild('Events')
local staminaGui = gui:WaitForChild('Stamina')
local staminaBar = staminaGui:WaitForChild('Frame'):WaitForChild('Frame')
local staminaEvent = events:WaitForChild('Stamina_Event')
local currStamina = 100
function updateStamina()
staminaBar:TweenSize(UDim2.new(currStamina / 100, 0, 0.5, 0), 'Out', 'Quad', 0.1)
end
userInputService.InputBegan:Connect(function(input, event)
if event or currStamina <= 0 then
return
end
if input.KeyCode.Name == 'LeftShift' then
staminaEvent:FireServer('sprint', 24)
repeat
if humanoid.MoveDirection.Magnitude > 0.1 then
currStamina = currStamina - 1
updateStamina()
end
wait()
until not userInputService:IsKeyDown(Enum.KeyCode.LeftShift) or currStamina <= 0
staminaEvent:FireServer('sprint', 16)
if currStamina <= 0 then
wait(2)
else
wait(1)
end
while not userInputService:IsKeyDown(Enum.KeyCode.LeftShift) and currStamina < 100 do
currStamina = currStamina + 1
updateStamina()
wait(0.4)
end
end
end)
SERVER:
events:WaitForChild('Stamina_Event').OnServerEvent:Connect(function(player, request, data)
if request == 'sprint' then
player.Character.Humanoid.WalkSpeed = data
end
end)

2 comments
currStamina = math.min(currStamina+1, 100)?I discovered that the value stays 100 with your method, but the GUI still tweens further than normal.