Im trying to position a frame so it will be in the exact center of the parent frame, having some trouble.
Set the the AnchorPoint of the frame you want to center to {0.5,0.5} and then for the position property put it to be {0.5,0,0.5,0}.
I have it at the AnchorPoint of .5,.5 but I need to position in different frames not just one frame
edit: do you mean use scale instead of offset? @xZylter
edit2: alright hold on give me a second @xZylter
Could you show pictures of what you mean by this?
You can use scale or offset but scale will be easier to have it align with center for any Frame because scale is a ratio of the size of the parented GuiObject and not a direct value.
Alright well here is the video of whats going wrong, this is when I just set the position of the ImageLabel to the frame
@xZylter
edit :
item.Position = slot.Position
Are all of the slots using AnchorPoints of 0.5,0.5?
No they arent I thought you said only the item I want to center
object hierarchy :
Well I was unaware of your use case, I would try setting all of the slots to have an AnchorPoint of 0.5,0.5 since that’s where the Position property is determined.
Yeah I’m stumped on what must be changed. Could you show your full script?
Sure here ya go
if equation then
print(item.Name.." is close to "..slot.Name)
item.Parent = slot
item.Position = slot.Position
end
Hmm, try using Position in the Properties window. That usually works for me.
Oh, nevermind I tried
local function positionInCenter(item, slot)
local middleAnchorP = Vector2.new(.5, .5)
local slotMiddle = slot.AbsolutePosition+(middleAnchorP-slot.AnchorPoint)*(slot.AbsoluteSize*.5)
local newItemPos = slottMiddle+(middleAnchorP-item.AnchorPoint)*(item.AbsoluteSize*.5)
local guiParent = item:FindFirstAncestorWhichIsA("GuiBase")
newItemPos = newItemPos-guiParent.AbsolutePosition
item.Position = UDim2.FromOffset(newItemPos.X, newItemPos.Y)
end
Hold on Im gonna try this soon, thank you
edit : It didnt work sadly it just makes the frame go out of range of the whole entire screen @RoBoPoJu
You could place that frame inside of the specific frame that you want it to be inside of. From there you can set the anchor of the frame you want to be in the middle to {0.5, 0.5}, and then set the scaled position to be {0.5, 0.5}.
I edited it. The earlier version of the code set the item’s Position
to what its AbsolutePosition
was supposed to be (the first newItemPos
value is what should be the AbsolutePosition
). Does it now work?
Could we see the properties of the frame? Position and Size specifically.
I just made a work-around and it works fine now, thanks everyone