I want to make a stamina bar that is drained when the player is sprinting and increases when player isn’t sprinting, and the sprinting works, the stamina bar won’t resize when I sprint. I haven’t tried anything else since I have no idea.
This is the script for sprinting I put under starterplayerscripts:
local Players = game:GetService("Players")
local UIS = game:GetService("UserInputService")
local player = Players.LocalPlayer
local character = player.CharacterAdded:Wait()
local stamina = script.Stamina.Value
UIS.InputBegan:Connect(function(input, GPE)
if input.KeyCode == Enum.KeyCode.LeftShift then
repeat
task.wait(0.055)
character.Humanoid.WalkSpeed += 1
stamina -= 100/30
until character.Humanoid.WalkSpeed == 25
end
end)
UIS.InputEnded:Connect(function(input, GPE)
if input.KeyCode == Enum.KeyCode.LeftShift then
repeat
task.wait(0.055)
character.Humanoid.WalkSpeed -= 1
stamina += 100/45
until character.Humanoid.WalkSpeed == 16
end
end)
And this was put under the stamina bar:
local stamina = game:GetService("StarterPlayer"):WaitForChild("StarterPlayerScripts").Sprint.Stamina
stamina:GetPropertyChangedSignal("Value"):Connect(function()
script.Parent.Size = UDim2.fromScale(math.clamp(0.65*stamina/100, 0, 1), 0.713)
end)
Any help would be greatly appreciated!