Spawn parts inside boundaries of a square except for an area

First off, sorry if the title was a little confusing, I don’t know how to explain my problem well.

Essentially, I have a script that spawns parts inside of a square and moves them in one direction.

local RunService = game:GetService("RunService")

local Spawner = script.Parent
local Rand = Random.new()

local Rate = 25 -- per second
local Length = 8 -- studs
local Speed = 20 -- stud per second
local Lifetime = 5 -- seconds
local Thickness = 0.2 -- studs

local XSize = Spawner.Size.X
local YSize = Spawner.Size.Y

local Parts = {}

local function SpawnPart()
	local p = Instance.new("Part", workspace)
	local posoffset = (Spawner.CFrame.UpVector * Rand:NextNumber(YSize/2,-YSize/2)) + (Spawner.CFrame.RightVector * Rand:NextNumber(XSize/2,-XSize/2))
	p.Anchored = true
	p.CFrame = Spawner.CFrame + posoffset
	p.Size = Vector3.new(Thickness,Thickness,Length)
	return p
end

local b = 0

RunService.Heartbeat:Connect(function(t)
	for i,v in pairs(Parts) do
		v.CFrame += v.CFrame.LookVector * (t * Speed)
	end
end)

while true do
	Parts[#Parts + 1] = SpawnPart()
	wait(1/Rate)
end

I want the part spawning to neglect an area inside of the square, so that parts won’t spawn in the middle.

Thanks for the help!

Could repeatedly pick a random point inside the red rect and reject it if it happens to be in the pink rect. If your allowed area is only a small fraction of the actually allowed area then you should go for a different approach, because on average it will take too many attempts to find a good point.

Something like this:

function isPointInRect(point: Vector3, rectC0: Vector3, rectC1: Vector3): boolean
     --Search around or ask if you need help with this
end

function getPartRectCorners(part: BasePart): (Vector3, Vector3)
    
end

function isPointValidSpawnPoint(point: Vector3): boolean
    return isPointInRect(point, getPartRectCorners(redRectPart)) and not isPointInRect(point, getPartRectCorners(pinkRectPart))
end

function getRandomSpawnPoint(): Vector3
    local point
    repeat
        point = randomPointInRect( getPartRectCorners(redRectPart) )
    until isPointValidSpawnPoint(point)
    return point
end