Make buildings always in a different spot

I want these buildings to always be in a different spot so they dont collide, but I don’t know how.

(dont mind highlights roblox issue)

	for i,v in pairs(GameBase:SurroundingHexIn(GameBase:GetTilePos(TileMesh))) do

			local sTileData = GameBase:GetTile(v)
			local TileBody = GameBase:GetTileMesh(v)
			local TileBodyBuildings = #TileBody:GetChildren()
			
			if TileBodyBuildings == 5 then return end
			
			for i = 1,math.random(2,4) do

			local buildings = MiniBuildingFolder:GetChildren()
			local RandomBuilding = buildings[math.random(1, #buildings)]:Clone()

			if sTileData:GetAttribute("Building") then return end
				
			RandomBuilding.Parent = TileBody
			
			RandomBuilding:SetPrimaryPartCFrame(
             CFrame.new(TileBody.Position + Vector3.new(math.random(0.5,1), TypeData[sTileData:GetAttribute("type")].Size/2 * TileScale, math.random(0,1))))
			end
		end

code

1 Like

There is probably a more efficient way of doing this.

But what I’m thinking is: you could insert your CFrame into a table. Then whenever you make another new CFrame, check if you can find a identical CFrame to it, if so then generate a new one.

could you give me a example? –

1 Like