How do I check if a GUI as reached a certain size?

Right now I am making a XP bar, now I want this xp bar to cap out at a certain length. How do I detect this length?

heres my code:

xp.Changed:Connect(function()
	xpNeeded = math.floor(((level.Value * (level.Value - 1)) / 5.3) * 100) + 15
	xpText.Text = "XP: "..xp.Value
	xpNeededText.Text = "XP Needed: "..xpNeeded
	
	change = (xp.Value / xpNeeded) * 0.49
	xpBar:TweenSize(UDim2.new(change, 0, .2, 0), "In", "Linear", 0.5)
	if xpBar.Size > UDim2(0.46, 0, 0.48, 0) then
		xpBar.Size(UDim2.new(0.46, 0,0.48, 0))
	end
end)

I don’t believe you can compare the size to the Udim2 properties like that. Did you get any errors?
I think you may need to compare the X and Y properties of your xpBar instead.

local xScale, xOffset, yScale, yOffset =  
xpBar.Size.X.Scale,
xpBar.Size.X.Offset,
xpBar.Size.Y.Scale,
xpBar.Size.Y.Offset

xp.Changed:Connect(function()
    xpNeeded = math.floor(((level.Value * (level.Value - 1)) / 5.3) * 100) + 15
    xpText.Text = "XP: "..xp.Value
    xpNeededText.Text = "XP Needed: "..xpNeeded

    change = (xp.Value / xpNeeded) * 0.49
    xpBar:TweenSize(UDim2.new(change, 0, .2, 0), "In", "Linear", 0.5)
    if xScale > 0.46 and xOffset > 0 and yScale > 0.48 and yOffset > 0 then
	    xpBar.Size = UDim2.new(0.46, 0,0.48, 0)
    end
end)

u can use the GetPropertyChangedSignal()

xp:GetPropertyChangedSignal("Size"):connect(function()
	    ----do stuff here
end)

My solution was this:

xp.Changed:Connect(function()
	xpNeeded = math.floor(((level.Value * (level.Value - 1)) / 5.3) * 100) + 15
	xpText.Text = "XP: "..xp.Value
	xpNeededText.Text = "XP Needed: "..xpNeeded
	
	change = (xp.Value / xpNeeded) * 0.867
	if change > 0.867 then
		change = 0.867
	end
	xpBar:TweenSize(UDim2.new(change, 0, .2, 0), "In", "Linear", 0.5)
end)

It will check if the change is greater then GUI XSIZE, which is 0.867, then it will set it to equal.