Imagine that you have a square part (this works with any part though, this is for simplification). If we want to find a random position within the part, that position will have two limits on each axis (a lower one and a higher one). Since it’s a square, the same limits will apply for all 3 axis, so let’s analyse just one (the X axis):
Starting from the centre, if we want to reach one of the edges, we need to move half of the size of the square to reach one, so we’ll move 1/2 of the part’s size to get there.
Those 2 limits (for each axis) I mentioned earlier are the two sides of one axis of the square. Let’s
The upper and lower X limit’s will therefore be:
--As mentioned earlier, we start from the centre of the square (square.Position.X)
local upperXLimit = square.Position.X + square.Size.X / 2
local lowerXLimit = square.Position.X - square.Size.X / 2