Trying to make a stamina gui

local stm = script.Parent

local stmvalue = script.Parent.Stamina

local stmvalue2 = script.Parent.MaxStamina

stm.Changed:Connect(function()

stm:TweenSize(UDim2.new(stmvalue/stmvalue2 * .2,0,0.02,1),“In”,“Linear”,1)

end)

So I am trying to get this to work with two number values in the gui stamina and max stamina both being 100 so if they ever change in value it still works, it dosent move at all it could be a problem with my math I do not know.

1 Like

I noticed flaws in the code and updated it to this

local stm = script.Parent

local stmvalue = script.Parent.Stamina.Value

local stmvalue2 = script.Parent.MaxStamina.Value

stmvalue.Changed:Connect(function()

stm:TweenSize(UDim2.new(stmvalue/stmvalue2 * .2,0,0.02,1),“In”,“Linear”,1)

end)

1 Like

Just a little question, is stm a value object? And if so are Stamina and MaxStamina too?

1 Like

yesir they are both number values of 100

1 Like

My math is probably the problem I need it to work with any size stamina gui

1 Like

stmvalue is a number value for stamina its 100 stmvalue2 is max stamina also 100 then

stm is the thing im trying to tween

1 Like

You need to use the new value when tweening the UI. Here is what I mean:

local stm = script.Parent
local stmvalue = script.Parent.Stamina
local stmvalue2 = script.Parent.MaxStamina.Value

stmvalue.Changed:Connect(function(value)
    stm:TweenSize(UDim2.new(value/stmvalue2 * .2,0,0.02,1),"In","Linear",1)
end)
2 Likes

Yeah, as @RetributionVI said, script.Parent.Stamina is a reference to the object, not the value inside of it, so do script.Parent.MaxStamina.Value and script.Parent.Stamina.Value

1 Like

in the second code i thought i did that lol but the second code i posted makes my stamina line move only one time. and its far off from what its supposed to be ill try what he said and get back to you guys.

2 Likes

so i put this and it did not even print

local stm = script.Parent
local stmvalue = script.Parent.Stamina
local stmvalue2 = script.Parent.MaxStamina.Value

stmvalue.Changed:Connect(function(value)
print(“I see a change”)
stm:TweenSize(UDim2.new(value/stmvalue2 * .2,0,0.02,1),“In”,“Linear”,1)
end)

1 Like

Maybe there is something I am failing to understand?

1 Like

Can we see the code you are using to change the stamina value?

I am manually changing it as my player loads in for now for testing purposes

If it helps i also am using a local script but I do not see why that would effect anything.

Are you manually changing the value from the GUI that is in StarterGui or the GUI that is in your PlayerGui? I tested it and it seems to be working fine.

it is definately in the player gui

It is working perfectly fine for me. Check if you have everything in the right place maybe?

https://gyazo.com/d825f1d78917334299f0be8f5dfbf5b5

if you can check this out this is the model with the code it isnt working for me it isnt the whole gui just whats supposed to be working

https://www.roblox.com/library/4162626105/gui-bruh

I would post a picture or video but I can not.

Replace line 7 with:
stm:TweenSize(UDim2.new(value/stmvalue2 * .2,0,0.02,1),"In","Linear",1)

You were using a different type of " character.

1 Like