Trying to get a stamina gui I am working on to auto regen?

So stm is the bar im tweening, stmvalue is a number value for stamina stmvalue2 is the maxstamina also a number value, I have tried multiple ways of doing this ive had the number value go up but the bar not go up with it I do not know if its a tweening error were its being told to tween so much or not but this is the final product I came up with this and it dose not work at all I need the bar to always update based on the number for stamina. after so many problems and no errors i gave up so I hope someone can help heres the code.

local stm = script.Parent
local stmvalue = script.Parent.Stamina
local stmvalue2 = script.Parent.MaxStamina.Value
local rs = game:GetService(“RunService”)
stmvalue.Changed:Connect(function(value)
print(“changed”)
stm:TweenSize(UDim2.new(value/stmvalue2 * .236,0,0.02,1),“In”,“Linear”,1)

end)
– regen
rs.RendereStepped:connect(function()
wait()
print(“running”)
if stmvalue.Value > 100 then
print(“1”)
stmvalue.Value = stmvalue.Value + 20
elseif stmvalue.Value > 100 then
print(“2”)
stmvalue.Value = 100
elseif stmvalue.Value == 100 then
wait()
print(“3”)

end 

end)

– auto update for regen

rs.RenderStepped:connect(function()
wait()
stm:TweenSize(UDim2.new(stmvalue.Value/stmvalue2 * .236,0,0.02,1),“In”,“Linear”,1)
end)

Divide the stamina value by the maximum stamina value and put that in the X Size argument of the UDim2 value (this could be it).

You also spelled RenderStepped wrong on line 11.

When setting the size or position of a GUI object, use either the Size property or Offset property. You shouldn’t use both at the same time.

And for the sake of organisation and easier to see the text, please keep your code formatted by using 3 backquotes (`) at the start and end of your code block.

1 Like

My bad, and i may not have explained the situation very well up top so If i change the number value my just typeing it in it works fine, although if I link it to a weapon that is being worked on and it is clicked multiple times for some reason the number wants to go back up but the actual stamina bar dose not.

I honestly don’t understand your question.
At which condition will the stamina regenerate and vice versa?