Problem with :TweenSize

Basically what i’m doing is an oxygen system for my game, and i am currently making the oxygen bar.

The problem is i’m using TweenSize for the bar and this is my current script:

wait(0.2)

while true do
	local hp = game.Players.LocalPlayer.Oxygen
	script.Parent:TweenSize(UDim2.new(0, 15, 0, hp.Value), "Out", "Sine", 0.15)
	wait(0.2)
end

It does work, kind of because when i go play and change the value this is what i get:

image

When it’s supposed to be the other way around.

Does anyone know how to fix this?

1 Like

Set the AnchorPoint of the GUI you’re resizing to 0, 1.

2 Likes

I recommend using humanoid.HealthChanged so you don’t have a running loop when you don’t need one.

I’m not doing a health bar, but i appreciate the advice

Sorry, I just saw hp and assumed it was health :joy: You can use Oxygen:GetPropertyChangedSignal(“Value”) instead so it only fires when the value changes

Fun fact, with value objects specifically you can just use .Changed:

game.Players.LocalPlayer.Oxygen.Changed:Connect(function(oxygen)
    script.Parent:TweenSize(UDim2.new(0, 15, 0, oxygen), "Out", "Sine", 0.15)
end)
2 Likes

Great! One less loop to lag my game.