How to make parts spawn in a odd sized area?

I’ve been trying to figure out how to make parts spawn in an unsymmetrical area, but I can’t think of an idea myself nor any sources that could help

this is my current script, which works fine for a symmetrical area, but I want it to be able to wrap around buildings without spawning inside of them

local area = game.Workspace.SpawnArea

local x = area.Size.X/2
local y = area.Size.Y/2
local z = area.Size.Z/2

local function spawn()
	local newPart = Instance.new("Part")
	newPart.Position = area.Position + Vector3.new(math.random(-x, x), math.random(-y, y), math.random(-z, z))
	newPart.Parent = game.Workspace
end

while wait(5) do
	spawn()
end

and here’s an example image of what I mean by an unsymmetrical area:

I’ve ended up going with something like this, don’t know if its the most optimal, but I’ll put it here incase someone has a similar problem

local function spawn()
	local newPart = Instance.new("Part")
	
	local SpawnAreas = game.Workspace.SpawnArea:GetChildren()
	local area = SpawnAreas[math.random(1, #SpawnAreas)]
	
	local x = area.Size.X/2
	local y = area.Size.Y/2
	local z = area.Size.Z/2
	
	newPart.Position = area.Position + Vector3.new(math.random(-x, x), math.random(-y, y), math.random(-z, z))
	newPart.Parent = game.Workspace
end

while wait(5) do
	spawn()
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.