Using absolute size to size gui isn't working

I’m trying to use absolute size to size a gui frame. However, despite doing this the frame is too small.
image
What could be the cause of this problem?

As far as I know you can’t use absolute size to size a UI, because absolute size is read-only.

Why are you trying to use AbsoluteSize? If you want your UI to scale automatically, you should size using scale.

1 Like

AbsoluteSize is basically just the pixel size, so you can use the offset part of UDim2 to size via AbsoluteSize.

I’m trying to tween a popup (which is parented to a different ScreenGui) towards the larger logo. I’m using absolute position(which seems to be working) to position it, and absolute size to size it. It is working for the 2 other frames I have, but not this one.

My code:

local correspondingAbsolutePos = correspondingIcon.AbsolutePosition
		local correspondingSize = correspondingIcon.AbsoluteSize
		
		local goalPos = UDim2.new(0, math.round(correspondingAbsolutePos.X, 1), 0, math.round(correspondingAbsolutePos.Y+Y_OFFSET, 1))
		local originalSize = UDim2.new(0, math.round(correspondingSize.X, 2), 0, math.round(correspondingSize.Y, 2))
		
		Icon.Size = originalSize + UDim2.new(0, 0.25, 0, 0.25)
		
		local tween = TweenService:Create(Icon, TweenInfo.new(0.65), {Position = goalPos})
		tween:Play()

You’d have to use UDim2 to set its position, and put the X and Z as the offset.

Also, entirely optional, but I would recommend using a custom tween function to make it a bit cleaner:

local tweenService = game:GetService('TweenService')
function tween(object,array,speed,style,direction)
	style = style or Enum.EasingStyle.Linear
	direction = direction or Enum.EasingDirection.InOut
	local tweenInfo = TweenInfo.new(speed,style,direction)
	return tweenService:Create(object,tweenInfo,array)
end

In this function, style and direction are optional and have the default of Linear and InOut.

I’m extremely confused as to what you want me to do. I am using Udim2 to set the position, but I don’t know what you mean by using the X and the Z as the offset. I can only use variables X and Y

Sorry, I meant X and Y and I see that you did that now. I’m very tired and should probably get off soon.

I don’t really see any issues with what you’ve shown (although I might be missing it). Are the other two frames using the same code? Are there any errors?

Yeah the code is being handled in one script. There are no errors. I honestly don’t know why it’s happening.

If it works for all but one, then there’s probably something different about that one. I definitely feel like there’s missing information here as to what the cause could be. From my experience of debugging, it can be something really minor that you might not even think is wrong.

Yeah potentially. I don’t really know what properties I should be looking for, though.

What I always do is read through my code logically line-by-line in the order it’s meant to execute. Read everything carefully and make sure you’re thinking of all sorts of possibilities without missing anything. I wish I could provide more help, but I don’t have enough information to work with atm.

But good luck, I’ll be heading off to sleep now :+1:

Yes, but in the initial message he’s saying he’s using absolute size size it … which I assumed meant he’s trying to do UI.AbsoluteSize =

Guess he meant he’s using AbsoluteSize to calculate the size

1 Like

That’s what I was going to say. There’s no point to make a whole topic on the dev forums over something that you want to do but doesn’t work even though there’s a way easier option to fix your issue.

Makes sense, I will try making a good script for this issue.

I’m still confused though, what does he want the script to do exactly? I have my idea of what he wants it to be here;

local UI_Element = script.Parent -- replace with your UI element

UI_Element.Size = UDim2.new(0, UI_Element.AbsoluteSize.X, 0, UI_Element.AbsoluteSize.Y)

This script first calls the updateSize function to set the initial size, and then connects the updateSize function to the AbsoluteSize changed event. This way, the size of the UI element will be updated whenever its AbsoluteSize changes. Please replace UI_Element with your actual UI element.

Please note that this script should be run after the UI element has been parented to the screen, as AbsoluteSize is dependent on the element’s parent. If the element is not on the screen, AbsoluteSize will be (0, 0) . If you want to keep the UI size updated even when it changes, consider using the GetPropertyChangedSignal("AbsoluteSize") event. This event fires whenever the AbsoluteSize property of the UI element changes.

I mean … you shouldn’t be asking me, haha. I just read the initial message, and that’s what I thought it said.

1 Like

Yeah, my bad. But you still helped me understand the issue a bit more!

1 Like

Well, seems like I found what he wants.

Your script seems to be correct, but it’s missing the part where you actually play the tween. The TweenService:Create() function creates a tween, but it doesn’t play it. You need to call the :Play() method on the returned tween to start it. Here’s how you can modify your function to do that:

local tweenService = game:GetService('TweenService')

function tween(object, array, speed, style, direction)
    style = style or Enum.EasingStyle.Linear
    direction = direction or Enum.EasingDirection.InOut
    local tweenInfo = TweenInfo.new(speed, style, direction)
    local tween = tweenService:Create(object, tweenInfo, array)
    tween:Play()  -- play the tween
    return tween
end