How to create a Selection Box

Hello, I am currently working on a large project which is only in its conception. And I am stuck on one point, how to make a selection box such as the one found on Roblox studio.

I thought about using the ray cast, but scanning a whole rectangle might not be very efficient, do you have any solution?

1 Like

The attached image is the roblox selection box, an example of what I want to do.

There is a Instance called SelectionBox, maybe this could help you understand it.

That’s not exactly what I’m talking about, I’m talking about the square drawn with the mouse. :sweat_smile:

This should work perfectly. Once you open this you put it in starter gui then you can start to scale the frame inside of it, pretty sure this is what you where looking for.

HoverUI.rbxm (2.2 KB)

You’re almost there, which interests me being the next step. How to know which parts are in the frame. :joy:

Wdym? You can scale the first frame inside the screengui, its called “1”, Once you scale it, it should be acting correctly and working perfectly.

Are you doing it on purpose? You just got the roblox interface, what interests me is not how to draw a frame, I think I’m big enough to do it on my own but how to code a system like this.

Oh… Well you can use UserInputService and check when a input begans and if its Enum.UserInputType.MouseButton1 you want to get the mouse position and update the frame each RenderStepped then when it input ends destroy the ui or disable it.

I want to do something like this.

Salutations Zayer

I can’t seem to understand your question very well but, you could do something similar to this :

  1. Determine the world positions of each corners, using :ScreenPointToRay()

  2. Iterate through the instances, to significantly reduce the amount of parts to loop, you could put the selectable parts in a certain folder

  3. Check whenever the instance is within the rectangle bounds by comparing their positions or using :ToObjectSpace(), if so you could insert the part into an array

  4. Speaking performance-wise, you can still improve a lot and this isn’t any case the optimized way.

I can’t provide any code sample since I’m quite busy, but that’s pretty much how you could conceive that.

Hey, thank you, this is exactly what I wanted, I will experiment a little in order to have a good result, really thank you :D.

1 Like