When I spam the shift keybind (run keybind) it drains my stamina faster, then when i stop spamming the keybind my stamina regains much faster then normal. Ive tried many fixes but none of them worked, if you need any more information id be happy to provide
code below:
local PS = game:GetService(“Players”)
local TS = game:GetService(“TweenService”)
local UIS = game:GetService(“UserInputService”)
local CoreEvent = game.ReplicatedStorage:WaitForChild(“CoreEvent”)
local Player = PS.LocalPlayer
– Helper to get all GUI references safely
local function getGuiRefs()
local CoreGui = Player.PlayerGui:FindFirstChild(“CoreGUI”)
if not CoreGui then return nil end
local InfoFrame = CoreGui:FindFirstChild(“InfoFrame”)
local RoundFrame = CoreGui:FindFirstChild(“RoundFrame”)
if not InfoFrame or not RoundFrame then return nil end
return {
CoreGui = CoreGui,
InfoFrame = InfoFrame,
RoundFrame = RoundFrame,
PlayerImageLabel = InfoFrame:FindFirstChild(“PlayerImageLabel”),
CurrentHealthTextLabel = InfoFrame:FindFirstChild(“CurrentHealthTextLabel”),
CurrentStaminaTextLabel = InfoFrame:FindFirstChild(“CurrentStaminaTextLabel”),
HealthTextLabel = InfoFrame:FindFirstChild(“HealthTextLabel”),
StaminaTextLabel = InfoFrame:FindFirstChild(“StaminaTextLabel”),
}
end
local guiRefs = nil
– Function to update all GUI refs when CoreGUI is re-added
local function updateGuiRefs()
guiRefs = getGuiRefs()
if guiRefs and guiRefs.PlayerImageLabel then
guiRefs.PlayerImageLabel.Image = PS:GetUserThumbnailAsync(Player.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size150x150)
end
end
– Listen for CoreGUI being added/re-added
Player.PlayerGui.ChildAdded:Connect(function(child)
if child.Name == “CoreGUI” then
– Wait for frames to exist
child:WaitForChild(“InfoFrame”, 2)
child:WaitForChild(“RoundFrame”, 2)
updateGuiRefs()
end
end)
– Initial setup
if Player.PlayerGui:FindFirstChild(“CoreGUI”) then
updateGuiRefs()
end
– Health and Stamina Changed connections
local function onHealthChanged()
if not guiRefs then updateGuiRefs() end
if guiRefs and guiRefs.CurrentHealthTextLabel and guiRefs.HealthTextLabel then
local HealthTween = TS:Create(guiRefs.CurrentHealthTextLabel, TweenInfo.new(0.2, Enum.EasingStyle.Quad, Enum.EasingDirection.Out),
{Size = UDim2.new(0, Player.HealthAmount.Value * 1.78, 0, 24)})
HealthTween:Play()
guiRefs.HealthTextLabel.Text = math.round(Player.HealthAmount.Value) … “/100”
end
end
local function onStaminaChanged()
if not guiRefs then updateGuiRefs() end
if guiRefs and guiRefs.CurrentStaminaTextLabel and guiRefs.StaminaTextLabel then
local StaminaTween = TS:Create(guiRefs.CurrentStaminaTextLabel, TweenInfo.new(0.2, Enum.EasingStyle.Quad, Enum.EasingDirection.Out),
{Size = UDim2.new(0, Player.StaminaAmount.Value * 1.78, 0, 24)})
StaminaTween:Play()
guiRefs.StaminaTextLabel.Text = Player.StaminaAmount.Value … “/100”
end
end
if Player:FindFirstChild(“HealthAmount”) then
Player.HealthAmount.Changed:Connect(onHealthChanged)
end
if Player:FindFirstChild(“StaminaAmount”) then
Player.StaminaAmount.Changed:Connect(onStaminaChanged)
end
– If HealthAmount or StaminaAmount are added later (e.g. after respawn)
Player.ChildAdded:Connect(function(child)
if child.Name == “HealthAmount” then
child.Changed:Connect(onHealthChanged)
end
if child.Name == “StaminaAmount” then
child.Changed:Connect(onStaminaChanged)
end
end)
local Running = false
local SprintLoop = nil
– Stamina regen control
local StaminaRegenActive = false
local function StaminaRegen()
if StaminaRegenActive then return end
StaminaRegenActive = true
task.wait(0.7)
while not Running and Player.StaminaAmount.Value < 100 do
task.wait(0.075)
Player.StaminaAmount.Value += 1
if Player.StaminaAmount.Value >= 100 then
Player.StaminaAmount.Value = 100
break
end
end
StaminaRegenActive = false
end
local function setSprintState(state)
if state == Running then return end
Running = state
if Running then
if Player.Character and Player.Character:FindFirstChild(“Humanoid”) then
Player.Character.Humanoid.WalkSpeed = 20
end
SprintLoop = coroutine.create(function()
while Running do
task.wait(0.15)
Player.StaminaAmount.Value -= 1
if Player.StaminaAmount.Value <= 0 then
Player.StaminaAmount.Value = 0
if Player.Character and Player.Character:FindFirstChild(“Humanoid”) then
Player.Character.Humanoid.WalkSpeed = 12
end
Running = false
break
end
end
end)
coroutine.resume(SprintLoop)
else
if Player.Character and Player.Character:FindFirstChild(“Humanoid”) then
Player.Character.Humanoid.WalkSpeed = 12
end
StaminaRegen()
end
end
– Keyboard sprinting (PC)
UIS.InputBegan:Connect(function(Input, processed)
if Input.UserInputType == Enum.UserInputType.Keyboard and not processed then
if Input.KeyCode == Enum.KeyCode.LeftShift then
setSprintState(true)
end
end
end)
UIS.InputEnded:Connect(function(Input, processed)
if Input.UserInputType == Enum.UserInputType.Keyboard and not processed then
if Input.KeyCode == Enum.KeyCode.LeftShift then
setSprintState(false)
end
end
end)
– Mobile sprinting (button)
local function setupMobileSprint()
– Wait for the BindableEvent from SprintButtonHandler
for i = 1, 60 do
if _G.MobileSprintBindable then break end
task.wait(0.05)
end
if not _G.MobileSprintBindable then return end
local toggled = false
_G.MobileSprintBindable.Event:Connect(function(action)
if action == "SprintStart" then
setSprintState(true)
elseif action == "SprintEnd" then
setSprintState(false)
elseif action == "SprintToggle" then
toggled = not toggled
setSprintState(toggled)
end
end)
end
if UIS.TouchEnabled then
task.spawn(setupMobileSprint)
end
local BreakLoop = true