How to prevent a Ui to get to the other side?

Hello there,

  1. What do you want to achieve? I want the black Ui not to get past the red line

So, the objective is to prevent the black Ui from going to the other side.

  1. What is the issue? I don’t know how

  2. What solutions have you thought of so far? looking in it’s properties

Note:

  • i want the size and the position of the “black Ui” to be set as “Scale” (not offset)

  • i want the size and the position of the “red Ui” to be set as “Offset” (not scale)

  • I also want to avoid doing it through a script

Thank you for your help :smiling_face: .

3 Likes

This is in the wrong category, also there is no way to prevent this however they cant move the UI like that, That only happens in studio but any real developer would be using a set resolution. Because if you do not, your UI will not scale correctly

2 Likes

@DyzuOfficial Oh sorry, in the description of this category, it mentioned the word User experience, i must have got confused between UX and Ui :sweat_smile:.

1 Like

If the red ui’s position HAS to be in offset, your only option is to use a script that alters the offset value every time the viewport size changes. Or just convert it to scale (could also be done by script)

1 Like

is there a way not to use a script for this problem?

3 Likes

You could use a UIAspectRatioConstraint in a frame containing the red line and the square and make the ratio fit what you like and then no matter the screen resolution the ui will always be the same proportions

2 Likes

Like that? :sweat_smile: :

image

In this video i’ll be showing the properties of the UiAspectRatioConstraint, and what happens when i shrink it:

Put the ui aspect ratio inside the Frame not inside “Yellow”

Do I have to change something in the propertie of the Ui aspect ratio?

Change the ratio until it looks good enough for you
I recommend something between 1.25 or 1.35

What about the yellow’s properties (for example: the size and position, should they be set to scale or offset)?

Everything in your ui should be scale
You should almost never use offset as it doesn’t scale to fit the screen size

But i rlly want red to be in offset

If you don’t know how to convert offset to scale simply do :

Scale = offsetPosition / the parent frame absolute size

It’s important for Red to be in offset

Heya, for me there are 2 ways you can go on this:

OffsetSizing.rbxm (9.3 KB)

With UIPadding

Easiest Method so far.

  1. Create a Frame (Yellow UI) for use as the parent.

  2. The Yellow UI should have an AnchorPoint opposites of the reference point (the Red UI). For example if the Red UI has an AnchorPoint of 0, 0.5 (attached to the left side of the screen) then the Yellow UI should have 1, 0.5 (attached to the right side of the screen).

  3. Set the Yellow UI size with a scale of 1 while adjusting the offset to the position of the reference point. For example if the Red UI is 600px away from the AnchorPoint, then the Yellow UI size should be {1, -600}, {whatever you need, whatever you need}

  4. Put the Black UI and UIPadding inside the Yellow UI.

  5. Adjust the UIPadding as needed.

No Parent

Will need a bit of math & calculation to follow.

  1. Make sure the Black UI have an AnchorPoint opposites of the reference point (the Red UI). For example if the Red UI has an AnchorPoint of 0, 0.5 (attached to the left side of the screen) then the Black UI should have 1, 0.5 (attached to the right side of the screen).

  2. Position the Black UI as follows = {The Black UI AnchorPoint.X, +/- Distance between the BlackUI's AnchorPoint to the closest side of the screen the AnchorPoint is},{Whatever,Whatever}. (try either using + or - for it, just see which one work)

  3. Size the Black UI as follows = {1,(Offset of the Red UI x -1) - (Distance between the Black UI and the Red UI + Distance between the BlackUI's AnchorPoint to the closest side of the screen the AnchorPoint is)},{Whatever, Whatever}

  4. Make sure the Black UI has a UISizeConstraint within, as so it wont scale it size below 0 to the negatives.

Calculation Example

Lets say that:

  • Your Red UI offset is 600px in the X axis, away from the left side of the screen
  • The Frame (Black UI) AnchorPoint is 1,0
  • You want the space between the Black UI and the Red UI about 30px
  • You want the space between the Black UI’s AnchroPoint and the left side of the screen about 40px

Then for Position would be:

  • Position = {1, -600},{0.5,0}

While the Size would be:

  • Size = {1,(600 x -1) - (30 + 40)},{1, 0}
  • Size = {1,(-600) - (70)},{1, 0}
  • Size = {1, -670},{1, 0}

These methods aren’t perfect though, as if the UI is off the screen, it can still be visible at some points. You can mitigate this by enabling ClipDescendant or better make a script that can handle the visibility of the Black UI.

Other than that, I do also want to warn you not to always use Scale for everything as @Aqua_Turneur said, see my reasoning below.

Don't always use Scale in Everything

This is quiet a slippery slope. Though it is true that most of the time Scale is the go to option, it’s not always the case that everything need to be it as there are GUIs which Offset does better. You’d need to test it out and see if using either would be the best for it.

I’ve seen a lot of people misusing the Scale especially when using AutoScale plugin, which cause a lot of issue if used without truly understanding your UI needs.

If scalability is truly an issue with an Offset UIs, you can always use UIScale

Hope this helps! :happy3:

2 Likes

OMG THANK YOU SO MUCH!!! But which one do u recommend doing tho?

Personally, I’ll probably go for the ‘No Parents’ method, as I’m already used to doing small math like this and uses this style.

Though some people may prefer the one with UIPadding as the UI Structure is clearer and easier to understand, especially useful if you have multiple people working on the project.

It’s your project, your choice. Just see what’s fit best for you :wink:

~ Also don’t forget to mark it as a solution if you find it helpful ~

1 Like

Yeah ik thank you, i just gotta try it first to see if it actually works

@Pyrenol

What do u mean by space between Black Ui and Anchor point