This is a stamina bar (local) script for my game. But if you reset/die the left shift to sprint doesn't work. If you want to see how it works please play my game (https://www.roblox.com/games/6750846558/SCP-Foundation-ALPHA?) to see how it works. The Script is down below. images here (https://ibb.co/RhtvgwP) of the file system. NOTE that the GUI is cloned at the start of the game into game.players.(player_name).PlayerGui
local bar = script.Parent
local stamina = 100
local staminaRate = 1
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
local isSprinting = false
local uis = game:GetService("UserInputService")
uis.InputBegan:Connect(function(key, gameProcessed)
if gameProcessed or stamina == 0 then return end
if key.KeyCode == Enum.KeyCode.LeftShift then
isSprinting = not isSprinting
if isSprinting then
humanoid.WalkSpeed = 25
else
humanoid.WalkSpeed = 16
end
end
end)
while wait() do
if stamina == 0 and isSprinting then
isSprinting = false
humanoid.WalkSpeed = 16
end
if isSprinting and humanoid.MoveDirection.Magnitude > 0 then
stamina = stamina - 1
wait(staminaRate)
else
stamina = stamina + 1
wait(staminaRate)
end
stamina = math.clamp(stamina, 0, 100)
bar:TweenSize(UDim2.new((1/100) * stamina, 0, 1 ,0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 0.5)
end

4 comments
its because there is no loop
and where I need to but the loop at
What do you want the script to do question?
Its a stamina bar scipt. it works in-game but when you die/reset the left shift to sprint dosen't activate