function updateGui(current, max)
if currentStamina >= 999 then
tween:Play()
tween2:Play()
TextTween:Play()
else
StaminaBar.Transparency = 0
StaminaBackground.Transparency = 0.6
StaminaText.TextTransparency = 0
tween:Cancel()
tween2:Cancel()
TextTween2:Cancel()
TextTween2:Play()
end
players.LocalPlayer.PlayerGui.Stamina.Bar.Size = UDim2.new(((current/max)*0.3)-0.3, 298, 0, 50) --exact size of the bar
end
--the stamina system
userInputService.InputBegan:Connect(function(input)
if hum.MoveDirection == Vector3.new() then return end
if input.KeyCode == Enum.KeyCode.LeftShift then
if currentStamina >= staminaCost then
FullSprintAnim:Play()
hum.WalkSpeed = sprintSpeed
SprintFOVTween:Play()
end
elseif input.KeyCode == Enum.KeyCode.X then
if currentStamina >= staminaCost2 then
LightJogAnim:Play()
hum.WalkSpeed = jogSpeed
JogFOVTween:Play()
end
end
end)
-- Sprint Key Released
userInputService.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
SprintStoppedFOVTween:Play()
FullSprintAnim:Stop()
hum.WalkSpeed = walkSpeed
elseif input.KeyCode == Enum.KeyCode.X then
JogStoppedFOVTween:Play()
LightJogAnim:Stop()
hum.WalkSpeed = walkSpeed
end
end)
runService.Heartbeat:Connect(function()
if hum.WalkSpeed == sprintSpeed then
if currentStamina >= staminaCost and hum.MoveDirection ~= Vector3.new() then
currentStamina -= staminaCost
else
hum.WalkSpeed = walkSpeed
FullSprintAnim:Stop()
end
elseif hum.WalkSpeed == jogSpeed then
if currentStamina >= staminaCost2 and hum.MoveDirection ~= Vector3.new() then
currentStamina -= staminaCost2
else
hum.WalkSpeed = walkSpeed
LightJogAnim:Stop()
end
else
if currentStamina < maxStamina then
currentStamina += staminaRegen
elseif currentStamina > maxStamina then
currentStamina = maxStamina
end
end
updateGui(currentStamina, maxStamina)
end)
This might be the problem, as when you’re setting the size of the stamina bar you subtracted 0.3 from the scale X. That causes it to go past its limit due to its X size being a negative number when your stamina gets too low.
ive tried that; whatever i change it to the bar is inaccurate -0.3 is the only number the fits the bars size, but ever number seems to have the same problem (this is 0):
Uhh. I didn’t read all of this but maybe if you have a value or something, you can do like
“if value.Value = 0 then” and your regenerating stamina and when it’s max “if value.Value = (yourmaxhere) then” then stop the moving stamina bar.
Current / Max is the ratio used to find the length that the bar should be at any given moment. Clamping that value to 0 and 1 means that if Current is negative, or 0, the ratio is 0 and if Current is equal to max, or greater than max, the ratio is 1. For every other situation, the value will reside between 0 and 1. If the bar is still not the size you want it to be, then you should look towards adjusting the values you’re multiplying and adding onto the ratio value.
For instance, I used this code in a previous project to set the size of a hunger bar correctly.
UDim2.new((hungerValue / 100) * 0.2, 0, 0.75, 0)
hungerValue is set to the current value of hunger and is clamped from 0 to 100. At 0, the bar will have a size of 0. At 1, the bar will have a scale value of 0.2, which is the size I want it to be at max.
If current stamina somehow falls below 0, or exceeds 1000, the ratio will either be below 0 or above 1. For instance, if current stamina is -5, then -5 / 1000 < 0 which would make the bar shift to the left, and if current stamina is 1050, then 1050 / 1000 > 1, which would make the bar shift further to the right.
Clamp the ratio to ensure it stays between 0 and 1, then multiply it by a scale value that you want the bar to be at max size.
So for some reason the all mighty moderation bot decided to flag my post and it’s been 12 hours…
Here’s a short version of my post:
In your code:
UDim2.new(((current/max)*0.3)-0.3, 298, 0, 50)
You set the height correctly but the X is wrong. You get current/max which is good, the output range is 0 to 1. But then multiply by 0.3, output range is 0 to 0.3. Finally you -0.3, output range is 0 to -0.3.
Then you add 298 pixels on top of whatever negative size popped out.
If you want to keep your current gui layout you want to do something like: