I have a 2d world saving script, the world became too big to save, so I split it up into keys. I cannot figure out why it wont work with my loading script, the table appears nil for the "model2"
Here is my saving script:
local DSS = game:GetService("DataStoreService")
local modelDataStore = DSS:GetDataStore("&^$e")
local function getModelData(model)
local modelData = {}
local primaryPart = model.PrimaryPart
local position = model.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}
return modelData
end
game.ReplicatedStorage.Save.OnServerEvent:Connect(function(player)
game.Workspace.Check.Value = "Saving.." -- I assume this line is for debugging?
local allLists = {} -- list of models
local models = {}
allLists[1] = models
for _, model in pairs(game.Workspace.Blocks:GetChildren()) do
if #models > 999 then -- Start a new list
models = {}
allLists[#allLists + 1] = models -- record the new list in allLists
end
models[#models + 1] = getModelData(model)
end
for i, models in ipairs(allLists) do
modelDataStore:SetAsync(i == 1 and player.UserId or player.UserId .. "_" .. i, models)
end
print('done')
end)
Here is my loading script:
local DSS = game:GetService("DataStoreService")
local modelDataStore = DSS:GetDataStore("&^$e")
game.Players.PlayerAdded:Connect(function(player)
game.Workspace.plr.Value = player.Name
local models = modelDataStore:GetAsync(player.UserId)
local models2 = modelDataStore:GetAsync(player.UserId .. "_")
game.Workspace.Blocks:ClearAllChildren()
for _, modelData in pairs(models) do
local targetModel = modelData.ModelName
local information = modelData.Position
local variable = game.ReplicatedStorage:FindFirstChild(targetModel)
print(variable)
local newModel = variable: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 = game.Workspace.Blocks
end
for _, modelData2 in pairs(models2) do
local targetModel2 = modelData2.ModelName
local information2 = modelData2.Position
local variable2 = game.ReplicatedStorage:FindFirstChild(targetModel2)
print(variable2)
local newModel2 = variable2:Clone()
local position2 = Vector3.new(information2[1], information2[2], information2[3])
local lookVector2 = Vector3.new(information2[4], information2[5], information2[6])
newModel2:SetPrimaryPartCFrame(CFrame.new(position2, position2 + (lookVector2 * 5)))
newModel2.Parent = game.Workspace.Blocks
end
end)
Everything from models load, but models2 appears nil, not sure if the issue is coming from the saving or loading script, thoughts?
