I am trying to fix my stamina bar. When a player spams the shift key it makes the values go down faster
I have tryed adding checks to make it only allow the script to run one time but I am probably making it in the wrong spot.
Look at the bottom left blue bar.
What happens when you spam shift:
What happens when you hold shift:
function UpdateSprintbar()
local Sprintbar = script.Parent.Frame.Data.Stamina.StaminaBar
local Sprint = math.clamp(LocalPlayer:GetAttribute("Sprint") / LocalPlayer:GetAttribute("MaxSprint"), 0, 1)
Sprintbar.Size = UDim2.fromScale(Sprint, 1)
Sprintbar.Parent.TextLabel.Text = LocalPlayer:GetAttribute("Sprint") .. " / " .. LocalPlayer:GetAttribute("MaxSprint")
end
local UserInputService = game:GetService("UserInputService")
UserInputService.InputBegan:Connect(function(inputObject, gameProcessed)
if gameProcessed then return end
if inputObject.KeyCode == LocalPlayer:GetAttribute("Sprintkey") and not running then
running = true
while UserInputService:IsKeyDown(LocalPlayer:GetAttribute("Sprintkey")) and LocalPlayer:GetAttribute("Sprint") > 0 and running do
LocalPlayer:SetAttribute("Sprint",LocalPlayer:GetAttribute("Sprint") - 1)
UpdateSprintbar()
if running then
task.wait(1)
end
end
end
end)
UserInputService.InputEnded:Connect(function(input, isTyping)
if not isTyping then
if input.KeyCode == LocalPlayer:GetAttribute("Sprintkey") then
running = false
warn("not running")
while not running and LocalPlayer:GetAttribute("Sprint") ~= LocalPlayer:GetAttribute("MaxSprint") do
LocalPlayer:SetAttribute("Sprint",LocalPlayer:GetAttribute("Sprint") + 1)
UpdateSprintbar()
task.wait(1)
end
end
end
end)