How do I stop the arrow in stamina ui from shrinking when stamina goes down?

I am trying to make the blue arrow in the stamina ui I made keep its size while the stamina goes down can someone help please?

Code:

while task.wait() do
	
	if IsSprinting == true and SprintEnabled == true then
		Stamina = Stamina - 0.30
	elseif IsSprinting == false then
		Stamina = Stamina + 0.15
	end
	
	if Stamina <= 0 then
		if IsSprinting == true then
			IsSprinting = false
			Humanoid.WalkSpeed = 13
			RunAnimation:Stop()
			TweenModule.cameratween(false)
		end
	end
	
	if Stamina < MaxStamina then
		if IsStaminaVisble == false then
			IsStaminaVisble = true
			TweenModule.StaminoMeterTween(true)
		end
	else
		if IsStaminaVisble == true then
			IsStaminaVisble = false
			TweenModule.StaminoMeterTween(false)
		end
	end
	
	Stamina = math.clamp(Stamina,0,MaxStamina)
	
	bar:TweenSize(UDim2.new(
		(MaxStamina / MaxStamina * 0.5) * (Stamina / MaxStamina * 2), 
		bar.Size.X.Offset,
		bar.Size.Y.Scale, 
		bar.Size.Y.Offset
		), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0)
end

Video of issue:

Image of how the stamina is in explorer:
image
The imagelabel named “Arrow” is the blue arrow

Try using TweenService to tween the position. Tweening the size using :TweenSize is both deprecated and shouldnt be used to tween movement. Since you didnt provide how the stamina is calculated i cant make code for you.

Okay I edited the post to contain the entire code

It seems like in your code you tweened the bar multiple times. with separate methods. Alongwith that you are increasing it with a while task.wait() do, which speeds can vary. Would you like me to rewrite the code to make it more efficient (while making it work ofc)?

sure also the “TweenModule.StaminoMeterTween(true)” thing is just to make the staminometer appear and disappear when not needed

Ohh i see. Alright i will reply with the new code in a bit.

1 Like

Ensure that bars Anchor Point value is 0.5,0.5, and ensure that you adjust the StaminaIncrease/Decrease. Let me know if there are any issues in the code since i wrote it with no testing soo.

local RunService = game:GetService("RunService")
local ts = game:GetService("TweenService")

local staminaIncrease = 1
local staminaDecrease = 1

RunService.RenderStepped:Connect(function(deltatime)
	--Assuming that Stamina,Tweenmodule,IsSprinting,Runanimation,IsStaminaVisible, and Bar is declared before
	if IsSprinting and SprintEnabled then
		Stamina -= staminaDecreasePerSecond * deltatime
	elseif not IsSprinting then
		Stamina += staminaIncreasePerSecond * deltatime
	end
	
	if Stamina < 0 and IsSprinting then
		IsSprinting = false
		Humanoid.WalkSpeed = 13
		RunAnimation:Stop()
		TweenModule.cameratween(false)
	end

	if Stamina < MaxStamina and IsStaminaVisible == false then
		IsStaminaVisible = true
		TweenModule.StaminoMeterTween(true) -- stamino?
	elseif Stamina > MaxStamina and IsStaminaVisible == true then
		IsStaminaVisible = false
		TweenModule.StaminoMeterTween(false)
	end

	Stamina = math.clamp(Stamina,0,MaxStamina)
	
	local staminaRatio = Stamina / MaxStamina
	
	bar.Position = UDim2.new(staminaRatio,0,0.5,0)
	
end)

Found a problem:
image
Edit: nvm I fixed it

I decided to test it and it this happened:

I made the bar anchorpoint to be “0.5,0.5” like you said before that video of me testing it and its not working Edit: Nvm I found a fix

oh sorry i didnt see your message, I tested it in a enclosed game and removed all the dependant modules, It works perfectly, the issue is on your end, likely due to the images you’re using. I cant know what is wrong without having ALL of the code, which i dont want you to leak your game, try to debug the issue.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.