Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do i access the X property of the AnchorPoint property of something?

Here is my code.

local timer = Instance.new('TextLabel', script.Parent.SurfaceGui)
timer.AnchorPoint.X = 0.5

However, i have an error: X cannot be assigned to How do i access the X property of the AnchorPoint property of the TextLabel?

1 answer

✓ Accepted answer
timer.AnchorPoint = Vector2.new(0.5, timer.AnchorPoint.Y)

will change the X without changing Y

5 comments

0

Could you explain what that code does?

0

The AnchorPoint is a Vector2 type (hence has an X and a Y component), but the components are read-only, so instead of setting AnchorPoint.X = 0.5, we just set AnchorPoint's value to a Vector2 which has an X value of 0.5 and the current Y value of AnchorPoint, so we only changed the X coordinate this way.

0

I'll try now, thanks for answering!

0

Thank you, how do I assign this? timer.Position.X.scale = 0.5 "scale cannot be assigned to"

0

Sorry for the late answer. GuiObject.Position is of type UDim2. You can set it using UDim2.new(xScale, xOffset, yScale, yOffset). If you only wanted to change X.Scale then you could write timer.Position = UDim2.new(0.5, timer.Position.X.Offset, timer.Position.Y.Scale, timer.Position.Y.Offset)

This discussion is preserved as it was. New answers, comments, and votes are closed.