So I have a sprint button right now and I have a script that makes you sprint, but I want to make a stamina bar GUI that goes down and lowers your sprinting speed (when you have no stamina make it your default walkspeed) and goes back up when you stop sprinting. I have a sprint button instead of shift to sprint and I want to keep it that way if possible. Does anyone know how I can do this? (I’ll attach the existing code which is in a TextButton that makes you sprint below)
Ok that seemed confusing so basically what I want to do is when you click the sprint button your stamina goes down and then when you click the button again to walk I want it to go back up again
local button = script.Parent
local Players = game:GetService('Players')
local sprinting = false
local function sprint()
local player = Players.LocalPlayer
game.Workspace.Click:Play()
if not sprinting then
sprinting = true
button.Text = 'Sprint: On'
player.Character.Humanoid.WalkSpeed = 30
script.Parent.Parent.SprintNotif:TweenPosition(UDim2.new(0.012, 0, 0.861, 0),"In","Sine",0.1)
script.Parent.Parent.SprintNotif.TextLabel.Text = ("Sprinting")
else
sprinting = false
button.Text = 'Sprint: Off'
player.Character.Humanoid.WalkSpeed = 16
script.Parent.Parent.SprintNotif:TweenPosition(UDim2.new(0.012, 0, 0.861, 0),"In","Sine",0.1)
script.Parent.Parent.SprintNotif.TextLabel.Text = ("Walking")
wait(1)
script.Parent.Parent.SprintNotif:TweenPosition(UDim2.new(0.012, 0, 1, 0),"Out","Sine",0.1)
end
end
button.MouseButton1Click:Connect(sprint)