I am getting this error when TycoonDataManager attempts to load the saved objects:
ServerScriptService.TycoonDataManager:90: attempt to index nil with 'x' - TycoonDataManager:90
Stack Begin
Script 'ServerScriptService.TycoonDataManager', Line 90 - function deserialize - TycoonDataManager:90
Script 'ServerScriptService.TycoonDataManager', Line 121 - TycoonDataManager:121
Stack End
TycoonDataManager:
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(function(plr)
deserialize(plr)
end)
players.PlayerRemoving:Connect(function(plr)
unloadTycoonData(plr)
end)
game:BindToClose(function()
for i, plr in ipairs(players:GetPlayers()) do
serialize(plr)
end
end)
If anyone can help me fix this it will be appreciated!
Same error. Also I’d like to note the tutorial is over 2 years old
ServerScriptService.TycoonDataManager:90: attempt to index nil with 'x' - TycoonDataManager:90
Stack Begin
Script 'ServerScriptService.TycoonDataManager', Line 90 - function deserialize - TycoonDataManager:90
Script 'ServerScriptService.TycoonDataManager', Line 121 - TycoonDataManager:121
Stack End
Well, fixing the name of the saved value is only going to change what gets saved from now on, you still have a datastore full of stored tables with a “tramsform” entry. You have to check saved data for both, by trying to read both and checking for nil before trying to access x,y,z, and r. Then, resave the user’s data with the key name fixed.
SetPrimaryPart is not a valid member of Model "Part" - TycoonDataManager:90
Stack Begin
Script 'ServerScriptService.TycoonDataManager', Line 90 - function deserialize - TycoonDataManager:90
Script 'ServerScriptService.TycoonDataManager', Line 121 - TycoonDataManager:121
Stack End
It worked 1 time but after reloading into the game I get
ServerScriptService.TycoonDataManager:90: attempt to index nil with 'x' - TycoonDataManager:90
Stack Begin
Script 'ServerScriptService.TycoonDataManager', Line 90 - function deserialize - TycoonDataManager:90
Script 'ServerScriptService.TycoonDataManager', Line 121 - TycoonDataManager:121
Stack End
i dont know why do you get memory address instead of what i got in my roblox studio output (as i show on my screenshot)
table.foreach should print every each value inside that table if you did something like this table.foreach(table,print) this will print every each function inside table so like table.freeze, table.clear etc
in your case those are supposed to be values like string and cframe inside of transform
in short terms put this
table.foreach(saved,print)
because im trying to figure out what is inside of “saved” table