Gui's size randomly changes to 0,0,0,0 when tweening

I am making an audio visualizer. When I try to tween the size of the GUI, it tweens it to 0,0,0,0 instead of the UDim2 I entered.
There is no code in my game that tries to change the X offset to 0 at any point, yet it ends up at 0. How is that possible?

My code:

local Frame = script.Parent.Visualizer
local sound = script.Parent.Song

while true do
	for i,g in pairs(Frame:GetChildren()) do
		if g:IsA("Frame") then
			local num = math.clamp(sound.PlaybackLoudness*0.20,1,100)/100
			print(num)
			g.Size = UDim2.new(0,5,num,0)
			wait()
			--game:GetService("TweenService"):Create(g,TweenInfo.new(1.5,Enum.EasingStyle.Cubic,Enum.EasingDirection.In),{Size = UDim2.new(0,5,0,2)}):Play()
			g:TweenSize(UDim2.new(0,5,0,2), Enum.EasingDirection.In, Enum.EasingStyle.Cubic, 1.5, true)
		end	
	end
end

also they are in a UIListLayout in a Frame

Your Code is very hard to read due to the screenshot’s size, make sure you put your Code inside a lua code block

-- Example

Plus, why are setting the UDim2 to the offset and not on the Scale?

This gui is not meant to change size even on different resolutions.
I will edit the code to be in text

Update: I fixed it by manually making a loop that changes the size. I still don’t know why the tween wasn’t working, so I will leave this unsolved since the original issue was not solved

You are mixing scale and offset in this declaration:

g.Size = UDim2.new(0,5,num,0)

If you are using UDim2.new() then they are defined as this:

UDim2.new(xScale,xOffset,yScale,yOffset);

So you are mixing xOffset with yScale so it will probably mess-up in the tween where you are just using offsets, here:

UDim2.new(0,5,0,2)

To prevent this mix-up you can create UDim2’s using:

UDim2.fromOffset()

or

UDim2.fromScale()

Whichever is required, like so:

g.Size = UDim2.fromOffset(5,num);

That’s right, but I was more worried about the X offset somehow changing to 0. It works fine on the Y axis.

Maybe change the override to false on the last parameter. Your tweens are taking place over 1.5 seconds so they may not complete before the next is called (i.e. overridden by true as last param) which will inevitably blow the values eventually to max or min.

I noticed a very weird thing with cubic easing style. All it does is pretty much this so using a different type like Quad might be the best option

( dead post so no idea if its still a problem )

1 Like

it is indeed still a problem, thanks bro

1 Like