Get the size of a part's surface?

I have a game where I need to cut holes in parts to put teleporters inside of them.

However, the holes are cut into the surface of a part.

Most walls are so big in one direction, but thin in the other. The walls must be at least 5 studs wide and 8 studs tall.

How would I be able to get the size of a specific surface of a part using mouse.TargetSurface?

An idea I had:

mouse.Button1Down:Connect(function()

    target    = mouse.Target
    surface = mouse.TargetSurface
    if surface.Name == 'Front' then
           surfaceSize = Vector2.new(target.Size.X, target.Size.Y)
    end

end)

(This probably won’t work as I wrote it on mobile, but you get the idea I hope)

Is there a simpler / better way to do this?

2 Likes

If you knew the size of surfaces, the formel of area is A = X * Y.

Back and front share the same vectors, as well as left and right, top and bottom.

1 Like

Okay, thanks! So this would technically work?

minimumArea = 5 * 8

SF = mouse.TargetSurface.Name
part = mouse.Target
if SF == 'Front' or SF == 'Back' then
    if (part.Size.X * part.Size.Y) >= minimumArea then
        -- Big enough
    end
end

Then do the same with the other faces

Yes, that would technically work. I’m not sure which face again that has front and back. If something goes wrong, switch the X with Z.

1 Like

a) multiply is 1st so the β€œ(” is useless and the code will compare its size, so when it is 10 blocks wide and 4 block high, it will be 40 so it will be 8*5). use

is surfraceSize.X>=minX and surfraceSize.Y>=minY then
2 Likes

Oh yeah, of course! I forgot about that, thanks!
Also I just use parenthesis out of habit.