In my game, I plan to make plots for each of the players in the server. The plots are created when the server is started, but deleted and re-added to refresh if the player has left.
My problem is that the finished plots look like this when I start the server
I originally wanted to pre-place them, but then every time I wanted to change the plot, it would have me replacing all spawned plots manually, So instead I made it so on the start of the server it would place them. Which meant that they spawned like this.
it also gets worse whenever someone leaves and rejoins, with the white plates moving further and further out.
Here is the normal plot for reference.
Below you can find the code that is used for spawning the plots.
ModuleScript for managing
local GS = {}
-- Spawn Plot with given number
function GS.SpawnPlotFromID(ID)
local NewPlot = game.ReplicatedFirst.Plot:MoveTo(Vector3.new(0, 0, 0))
local Plots = workspace.Plots:GetChildren()
local PlotSpacing = 150
local NewPlot = game.ReplicatedFirst.Plot:Clone()
NewPlot.Parent = workspace.Plots
local AssingedPlayer = Instance.new("IntValue", NewPlot)
AssingedPlayer.Name = "AssignedPlayer"
AssingedPlayer.Value = 0
local PlotID = Instance.new("IntValue", NewPlot)
PlotID.Name = "PlotID"
PlotID.Value = ID
NewPlot:MoveTo(Vector3.new(100,0, PlotSpacing * (ID - 4)))
return NewPlot
end
-- Spawn All Plots when starting server
function GS.SpawnPlots()
for count = 1, 8, 1 do
GS.SpawnPlotFromID(count)
end
end
function GS.DeleteAllPlots()
for i, plot in pairs(workspace.Plots:GetChildren()) do
GS.DeleteSlots(plot.PlotID.Value)
plot:Destroy()
end
end
-- Assign Plot to Player
function GS.AssignPlotToPlayer(player)
local Plots = workspace.Plots:GetChildren()
local playerID = player.UserId
for i, plot in pairs(Plots) do
if plot.AssignedPlayer.Value == 0 then
plot.AssignedPlayer.Value = playerID
GS.BringPlayerToPlot(player)
return plot
end
end
end
function GS.GetPlotFromID(PlotID)
local Plots = workspace.Plots:GetChildren()
for i, plot in pairs(Plots) do
if plot.PlotID.Value == PlotID then
return plot
end
end
end
-- Find A Plot Belonging to Given Player
function GS.GetPlotFromPlayer(player)
local playerID = player.UserId
local Plots = workspace.Plots:GetChildren()
for i, plot in pairs(Plots) do
if plot.AssignedPlayer.Value == playerID then
return plot
end
end
end
-- Reset Player's Plot After They Leave
function GS.ResetPlayersPlot(player)
local Plot = GS.GetPlotFromPlayer(player)
local PlotID = Plot.PlotID.Value
Plot:Destroy()
GS.SpawnPlotFromID(PlotID)
end
function GS.BringPlayerToPlot(player)
local Plot = GS.GetPlotFromPlayer(player)
local Character = player.Character
Character:MoveTo(Plot.SpawnPos.Position)
end
return GS
Server script for managing
local GS = require(game.ReplicatedStorage.GameSystem)
local DS = require(game.ReplicatedStorage.DataSystem)
for i,v in pairs(game.Workspace.PlotOutlines:GetChildren()) do
v:Destroy()
end
GS.SpawnPlots()
function PlayerSpawned(player)
player.CharacterAdded:wait()
local plot = GS.AssignPlotToPlayer(player)
local leaderstats = DS.CreateLeaderstats(player)
local Stats = DS.CreateStatsData(player)
end
function PlayerLeft(player)
GS.ResetPlayersPlot(player)
end
game.Players.PlayerAdded:Connect(PlayerSpawned)
game.Players.PlayerRemoving:Connect(PlayerLeft)
Also, the referenced files in the server script, GS and DS are two module scripts. GS is the one that spawns and manages the plots, named GameSystem, and DS is for datastores and leaderstats, so it has nothing to do with the spawn system.
Thank you in advance for any help.

