Plot Grid Spacing Help

hey there! i’ve been working on a system like horrific housing’s. i have a plot preset in replicated storage under a folder named Plots. ive been trying all day to make them spawn in a grid like way but i cant make it work… the script clones the plot in replicated storage and assigns a player in it, they then teleport to the plot they were assigned. i just want it to separate and make them spawn in a grid. if you have any questions to further understand let me know! here is my script including just the teleporting not the sorry attempt of putting them in a grid.

any help would be appreciated

local replicatedStorage = game:GetService("ReplicatedStorage")
local workspace = game:GetService("Workspace")
local plotModel = replicatedStorage:WaitForChild("Plots").plot
local playerPlots = {}

local function duplicatePlotsForPlayers(player)
	local plotClone = plotModel:Clone()
	plotClone.Parent = workspace

	playerPlots[player] = plotClone
end
local function teleportPlayerToPlot(player)
	local assignedPlot = playerPlots[player]
	if assignedPlot then
		local spawnLocation = assignedPlot:FindFirstChild("SpawnLocation")
		if spawnLocation then
			local character = player.Character
			if character then
				wait(1)
				local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
				humanoidRootPart.CFrame = CFrame.new(spawnLocation.Position)
			end
		end
	end
end

local function onPlayerJoined(player)
	player.CharacterAdded:Connect(function(character)
		duplicatePlotsForPlayers(player)
		teleportPlayerToPlot(player)
	end)
end

for _, player in pairs(game.Players:GetPlayers()) do
	onPlayerJoined(player)
end

game.Players.PlayerAdded:Connect(onPlayerJoined)

You can set a variable for the space between each plot in the grid. For example:

local Padding = 10 --studs

Then to arrange them in the grid, iterate through each “row” of players and then add how many plots are in each row:

for r = 0, rows do
   for p = 0, plots do
      --duplicatePlotsForPlayer(player)
      plotClone.Position = Vector3.new((plotClone.Size.X + Padding) * p, 0, (plotClone.Size.Z + Padding) * r)
   end
end

but then wouldn’t it have to be a part instead of a model?

Oh, I didn’t realize it’s a model.

Set the ground of the plot as the PrimaryPart of the model and say this instead:

plotClone:PivotTo(CFrame.new((plotClone.Size.X + Padding) * p, 0, (plotClone.Size.Z + Padding) * r))

let me try it. im not the best scripter so it might take me a while lol, ty for your help so far.

i cant get it working icl, it just doesnt give me any errors.

How is it not working? Are they being placed all in the same spot?

yeah, and i just suck at programming so