Getting the centre of a frame

I posted this like 2 days ago but the method shared didn’t work for what i wanted it to do. I’m looking for a method to get the centre of a frame that is inside another frame. this is a gui btw

Thanks in advance,
Dev_Taiga

To get the centre of anything just do Var.X/2, Var.Y/2

tried this, didn’t work out. It’s always off centre

How? It’s literally getting the middle on both axis’.

How exactly is it off centre

If you are trying to put something in the center it has to be UDim2.new(.5, 0, .5, 0) then subtract half of the scale of what you’re trying to put in the center.

https://gyazo.com/db3e03f6f82547f1464a0a7b2d5b1602

I’m looking to get the centre in a script not just centre a gui element

What do you want to use it for I don’t understand why UDim(.5, 0, .5, 0) isn’t the center, It should be.

Trying to make a inventory system that when you drag a ui element i can tell where it is when it’s being dropped onto something.

Can you screenshot the gui object and its descendants, I think the issue is something to do with the parenting, also make sure you’re using scale instead of offset if you want the center. If you want to make a system for it, I’d recommend looking in to UIGridLayout and AbsolutePosition depending on your approach. Both are useful for what you want, I’m just not sure the direction you’re taking it.

The math should be size1 + size2 / 2. Do that for X and Y and you’ll have the center.

Edit: You can also do the center of the inner frame but I think you wanted the center of both combined, correct?

Never mind, im an idiot completly forgot that .Draggable is a thing. Sorry for wasting your time T_T was literally trying to create my own draggable logic

1 Like

Draggable is deprecated so you should not use it. Creating your own draggable logic is the correct way to do so. Using deprecated features is ill-advised because they are likely to break.

To get the center of an object, you can do
frame.AbsolutePosition + (frame.AbsoluteSize / 2)
to get the Vector2 (x, y) center in pixels (offset).

2 Likes

whoever is reading this post, your problem maybe because you didn’t set your anchor point of your frame to 0.5