How do I position this UI?

Suppose I have a frame here, I want to move the frame’s X 0.5 studs away, here’s the code:

script.Parent.Position = UDim2.new(0,script.Parent.Position.X.Scale - 0.5,0,0)

However, the result turns into:
image

I even tried to print (script.Parent.Position.X.Scale - 0.5), it turns out to be an expected result, but why is the frame’s position 0,0,0,0? Did I do something wrong?
image

You’ve put your code in the Offset section of UDim2. Try:

script.Parent.Position = UDim2.new(script.Parent.Position.X.Scale - 0.5,0,0,0)

UDim2 is structured like (XScale, XOffset, YScale, YOffset). Offset is a value in pixels, and you can’t have half a pixel so the code you wrote wouldn’t do anything. Hope this helped! :slight_smile:

1 Like

Oh my bad! I mixed up the scale and offset, it works now. Thanks for the help :smiley:

2 Likes