UI Aspect Ratio Constraint Issue

Anyone who knows me can tell you that I’m by no means an expert programmer, so I apologize in advance if this problem is painfully obvious:

I’ve never worked with UI aspect ratio constraints before, so after modifying an open-source color picker GUI I’ve run into a problem with the placement of the cursor. The constraint seems to stay in the very center of the screen, so by shifting the position of the GUI, I can no longer select the color. I’ve done my share of fiddling with the script to try to get it to work with my limited experience with no luck.

colorselector
I believe this is the section of code that concerns this issue -

This is the explorer hierarchy -

hierarchy

This is the place file: Color Picker GUI.rbxl (28.3 KB)

(The GUI always seems to default to a darkened purple color whenever it’s initialized and I’m not sure why that is, so that’s another problem but it doesn’t have to be addressed here since it’s unrelated.)

Thanks!

2 Likes

Did you try setting the Anchor Point of the cursor to 0.5 on both values so positioning is based on the center of the image?

2 Likes

Yeah, the anchor point is centered:
anchorpoint

1 Like

When you define “d”, I do not think you need the Absolute Size factor in there. You just need to subtract the Absolute X and Y of the color picker from mouse x and y to position the cursor inside the picker.

local d = Vector2.new(x - colorselector.AbsolutePosition.X, y - colorselector.AbsolutePosition.Y)

And then you just use offset when positioning the cursor like:
colorchoice.Cursor.Position = UDim2.new(0, d.x, 0, d.y)

Also, you cannot divide Absolute Size by 2 because it is not a single value. You need to individually divide the X and Y by 2.

1 Like

I tried something similar to that earlier, it still stays in the center but seems to change how the mouse’s movements translate to the cursor’s position, not modifying the actual boundaries in which it can move.
update

(EDIT: Sent before your edits elaborating on your previous message, I’m looking into it further)

1 Like

local d = Vector2.new(x - colorselector.AbsolutePosition.X, y - colorselector.AbsolutePosition.Y)

I found the original line in the script to be more effective than this one in terms of positioning the cursor, as seen in the last post.

colorchoice.Cursor.Position = UDim2.new(0, d.x, 0, d.y)

This was the line that helped fix it, as it’s the one that dictates the position of the aspect constraint (I didn’t notice this while messing with the script earlier)⁠—by manually inputting the same position offset as the color wheel, the constraint now matches the wheel and it works now. Thanks!

com-video-to-gif%20(7)

1 Like