A private message is associated with this issue to @zblox164, the tutorial author
I’m using a tutorial to manage auto plot saving and claiming, but upon rejoining, I get an error in the output instead of the expected result. I did the fix he did for the error, but a different error keeps popping up in output.
ServerScriptService.ServerModules.PlotManager:16: attempt to index nil with 'Name' - PlotManager:16
Stack Begin
Script 'ServerScriptService.ServerModules.PlotManager', Line 16 - function returnPlot - PlotManager:16
Script 'ServerScriptService.TycoonDataManager', Line 109 - function unloadTycoonData - TycoonDataManager:109
Script 'ServerScriptService.TycoonDataManager', Line 121 - TycoonDataManager:121
Stack End
PlotManager (ModuleScript):
local plotManager = {}
function plotManager.assignPlot(loc,plr)
for i, plt in pairs(loc:GetChildren()) do
if plt.Owner.Value == "" then
plt.Owner.Value = plr.Name
break
end
end
end
function plotManager.returnPlot(loc,plr)
print(loc)
for i, plt in pairs(loc:GetChildren()) do
if plt.Owner.Value == plr.Name then
return plt
end
end
end
return plotManager
TycoonDataManager (ServerScript):
local players = game:GetService("Players")
local replicatedStorage = game:GetService("ReplicatedStorage")
local plotManager = require(script.Parent.ServerModules.PlotManager)
local dataStoreService = game:GetService("DataStoreService")
local dataStore = dataStoreService:GetDataStore("TycoonProgress2")
local tries = 3
local dataloaded = nil
local function serialize(plr)
if dataloaded then
local plot = plotManager.returnPlot(workspace.Plots, plr)
local key = plr.UserId
local count = 0
local data = {}
for i, obj in ipairs(plot.itemHolder:GetChildren()) do
table.insert(data, {
["name"] = obj.Name,
["tramsform"] = {
["x"] = obj.PrimaryPart.CFrame.X;
["y"] = obj.PrimaryPart.CFrame.Y;
["z"] = obj.PrimaryPart.CFrame.Z;
["r"] = obj.PrimaryPart.Orientation.Y
}
})
end
local success, err
repeat
success, err = pcall(function()
dataStore:SetAsync(key, data)
end)
count = count + 1
until count >= tries or success
if not success then
warn("Data could not be set." .. tostring(err))
return
end
else
warn("Data has not been loaded. Do not attempt to set data when it has not been loaded.")
return
end
end
local function deserialize(plr)
local plot = plotManager.returnPlot(workspace.Plots, plr)
print(plot)
local key = plr.UserId
local count = 0
local data
local success, err
repeat
success, err = pcall(function()
data = dataStore:GetAsync(key)
end)
count = count + 1
until count >= tries or success
if not success then
warn("Failed to read data." .. tostring(err))
plr:Kick("Failed to read data. Please rejoin the game.")
return
end
if data then
local plot = plotManager.returnPlot(workspace.Plots, plr)
print(plot)
for i, saved in ipairs(data) do
local loadedModel = replicatedStorage.Models:FindFirstChild(saved.name):Clone()
if loadedModel then
loadedModel:SetPrimaryPart(CFrame.new(saved.transform.x, saved.transform.y, saved.transform.z)*CFrame.Angles(0, math.rad(saved.transform.r), 0))
loadedModel.Parent = plot.itemHolder
else
return
end
end
dataloaded = true
return data
else
dataloaded = true
return {}
end
end
local function unloadTycoonData(plr)
local plot = plotManager.returnPlot(workspace.Plots, plr)
serialize(plr)
for _, obj in ipairs(plot.itemHolder:GetChildren()) do
obj:Destroy()
end
plot.Owner.Value = ""
end
players.PlayerAdded:Connect(deserialize)
players.PlayerRemoving:Connect(unloadTycoonData())
game:BindToClose(function()
for i, plr in ipairs(players:GetPlayers()) do
serialize(plr)
end
end)
All help appreciated!