Stamina UI is not working properly

Hello, I am having a problem with my stamina UI, I am not a scripter or a UI designer so I have no idea what cost this problem.

  1. What do you want to achieve? Keep it simple and clear!

A sprinting system with a stamina bar

  1. What is the issue? Include screenshots / videos if possible!

The issue is that the stamina bar is not working properly, when I press the button to start sprinting the stamina bar started to become weird. Here’s a video of the issue

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

Yes I did but I still have no idea how to fix it. I do not know if it’s a UI problem or a script problem.
Here’s the script (Keep in mind that I am not a scripter, I used an open source script I found which I understand some of the code)

local UIS = game:GetService('UserInputService')
local Frame1 = script.Parent:WaitForChild('Frame1'):WaitForChild('Frame2')
local player = game.Players.LocalPlayer
local NormalWalkSpeed = 16
local NewWalkSpeed = 100
local ii = 10
local running = false
repeat wait() until game.Players.LocalPlayer.Character
local character = player.Character

UIS.InputBegan:connect(function(key, gameProcessed)
	if key.KeyCode == Enum.KeyCode.Q and gameProcessed == false then
		character.Humanoid.WalkSpeed = NewWalkSpeed
		running = true
		while ii > 0 and running do
			ii = ii - 0.5
			Frame1:TweenSize(UDim2.new(ii / 10, 5, 1, 0), 'Out', 'Quint', .1, true)			
			wait()
			if ii <= 0 then
				character.Humanoid.WalkSpeed = NormalWalkSpeed
			end
		end
	end
end)

UIS.InputEnded:connect(function(key, gameProcessed)
	if key.KeyCode == Enum.KeyCode.Q and gameProcessed == false then
		character.Humanoid.WalkSpeed = NormalWalkSpeed
		running = false
		while ii < 10 and not running do
			ii = ii + 0.1
			Frame1:TweenSize(UDim2.new(ii / 10, 5, 1, 0), 'Out', 'Quint', .1, true)			
			wait()
			if ii <= 0 then
				character.Humanoid.WalkSpeed = NormalWalkSpeed
			end
		end
	end
end)

What is the size of the blue bar originally before spriting? I think it overextended the border because in the tween you are treating the x scale as a value of 1. What I mean is that when ii = 10, ii/10 will give a value of 1 making it overextend. This could be fixed by multiplying by the original scale factor on the x-axis. I think it’s the same for the y size. It is also being tweened to a y scale of 1

1 Like

Hey, that worked! Thank you but still have a little bit of problem. When the stamina is out there is a little bar thingy popping out at the end, here’s the video of it


How would I fix it to make it cleaner?

I think your ii value is becoming negative. Try clamping the ii value to prevent this.

ii = math.clamp(ii-0.5, 0, math.huge)

this will prevent it from going under 0. Other than that I am unsure what could be causing that.

1 Like