I have a sprinting system in my game, but when were you respawn the system stops working.
Sprinting is toggled by pressing Right Shift.
I have tried many things but I can’t figure it out. If you know to fix this then, please tell me.
local bar = script.Parent
local stamina = 100
local staminaRate = 1
local plr = game.Players.LocalPlayer
local char = plr.Character or plr:GetPropertyChangedSignal("Character"):Wait()
char = plr.Character
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
When turning ResetOnSpawn on the Script works but the UI element disappears
Before Respawn
After Respawn