How would i save a model's position based on the plot its on rather than where it is in the world.
What happens is that if a player saves on plot 1 then loads into plot 2, all their stuff is on plot 1 when they are on plot 2
Here is my code:
local datastore = game:GetService("DataStoreService")
local modelDataStore = datastore:GetDataStore("SavePlot")
local noobs = game:GetService("Teams"):FindFirstChild("Noobs")
local items = game.ReplicatedStorage.Items
local bases = game.Workspace.Explorers
game.Players.PlayerAdded:Connect(function(player) --load
repeat wait() until player.Team ~= noobs
local teamname = player.Team.Name
local models = modelDataStore:GetAsync(player.UserId)
local modelData = modelDataStore:GetAsync(player.UserId)
for _, modelData in pairs(models) do
local targetModel = modelData.ModelName
local information = modelData.Position
local newModel = items:FindFirstChild(targetModel):Clone()
local position = Vector3.new(information[1], information[2], information[3])
local lookVector = Vector3.new(information[4], information[5], information[6])
newModel:SetPrimaryPartCFrame(CFrame.new(position, position + (lookVector * 5)))
newModel.Parent = bases:FindFirstChild(teamname).ItemHolder
end
end)
game.Players.PlayerRemoving:Connect(function(player) --save
local team = player.Team
local teamname = team.Name
if player.Team ~= noobs then
local models = {}
for _, model in pairs(bases:FindFirstChild(teamname).ItemHolder:GetChildren()) do
local modelData = {}
local primaryPart = model.PrimaryPart
local position = primaryPart.Position
local direction = primaryPart.CFrame.lookVector
modelData.ModelName = model.Name
modelData.Position = {position.X, position.Y, position.Z, direction.X, direction.Y, direction.Z}
models[#models + 1] = modelData
print(modelData.ModelName)
end
modelDataStore:SetAsync(player.UserId, models)
print('done')
else
print("player is on starter team and has nothing loaded to save")
end
end)

1 comment
Just for the record the plots are arranged in a "+" facing the center and are all sized (78, 1, 42) if that helps