How can I make parts spawn only in a region3 area?

I want to make parts spawn inside a region3 area

So right now I’m using the .random property and i’m just wondering if theirs a way to use region3

local function ranPos()
	for i,v in pairs(part) do 
		v.CFrame = CFrame.new(math.random(0, 20), 0, math.random(0, 20))
	end
end

ranPos()
2 Likes

U set the math.random calls to the appropiate min and max values

yes but I’m not sure how to use this with region3

I think I am using a part as a region3 to spawn coins using the following

local newPart =
local Region = workspace.region
xS = Region.Size.X/2
zS = Region.Size.Z/2

local posX = math.random(x-xS,x+xS)
local posY = 5
local posZ = math.random(z-zS,z+zS)

newPart.Position = Vector3.new(posX, posY, posZ)