PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience
Collapse Sidebar

AbsolutePosition

GuiBase2d

Vector2

AbsolutePosition is a read-only property that provides the screen position of a UI element in pixels. This represents the actual pixel position at which an element renders as a result of its ancestors’ sizes and positions. The GuiObject/AnchorPoint also influences the AbsolutePosition. This property, GuiBase2d/AbsoluteSize and GuiBase2d/AbsoluteRotation are a group of properties that all describe the final rendered orientation of a UI element.

For example, on a 1920 by 1080 screen, a Frame with position {0.5, 0}, {0.5, 0} would have an AbsolutePosition of (960, 540). If you were to place another Frame with position {0, 50}, {0, 50} inside that one, its AbsolutePosition would be (1010, 590). This example assumes each Frame has the defualt GuiObject/AnchorPoint of (0, 0), the top left corner.


Code Samples


Copycat Frame

This code sample shows how a UI element’s size, position and rotation can be copied without parenting a “copycat” to the original. It uses the Absolute-family of properties to orient a “copycat” Frame that covers on the screen space that the original does.

-- Place within a Frame, TextLabel, etc.
local guiObject = script.Parent

-- For this object to be rendered, it must be a descendant of a ScreenGui
local screenGui = guiObject:FindFirstAncestorOfClass("ScreenGui")

-- Create a copy
local copycat = Instance.new("Frame")
copycat.BackgroundTransparency = 0.5
copycat.BackgroundColor3 = Color3.new(.5, .5, 1) -- Light blue
copycat.BorderColor3 = Color3.new(1, 1, 1) -- White

-- Orient the copy just as the original; do so "absolutely"
copycat.AnchorPoint = Vector2.new(0, 0) 
copycat.Position = UDim2.new(0, guiObject.AbsolutePosition.X, 0, guiObject.AbsolutePosition.Y)
copycat.Size = UDim2.new(0, guiObject.AbsoluteSize.X, 0, guiObject.AbsoluteSize.Y)
copycat.Rotation = guiObject.AbsoluteRotation

-- Insert into ancestor ScreenGui
copycat.Parent = screenGui