Hi, I’m trying to make a data-saving system for my sandbox factory tycoon.
When I place any items, and leave the game, it freezes for about 10 - 20 seconds, and then “Game shutdown deadline past” is in red in the output like 20 times.
I’m not sure what’s happening, but when I remove the model saving, it works normally.
Model saving script:
local function Serialize(prop) --prop will be the property's value type
local type = typeof(prop) --the type of the value
local r --the returned value afterwards
if type == "BrickColor" then --if it's a brickcolor
r = tostring(prop)
elseif type == "CFrame" then --if it's a cframe
r = {pos = Serialize(prop.Position), rX = Serialize(prop.rightVector), rY = Serialize(prop.upVector), rZ = Serialize(-prop.lookVector)}
elseif type == "Vector3" then --if it was a vector3, this would apply for .Position or .Size property
r = {X = prop.X, Y = prop.Y, Z = prop.Z}
elseif type == "Color3" then --color3
r = {Color3.toHSV(prop)}
elseif type == "EnumItem" then --or an enum, like .Material or .Face property
r = {string.split(tostring(prop), ".")[2], string.split(tostring(prop), ".")[3]}
else --if it's a normal property, like a string or a number, return it
r = prop
end
return r
end
local function GetFactoryData(Player)
local Items = workspace.base.itemHolder:GetChildren()
if #Items < 1 then return nil end
local ItemData = {}
for Each, Item in ipairs(Items) do
local ItemCF = Item:GetPivot()
local ItemName = Item.Name
local SerializedCFrame = Serialize(ItemCF)
table.insert(ItemData, {
DataName = ItemName,
DataCF = ItemCF
})
end
return ItemData
end
local FactoryTable = GetFactoryData(player) or {}
print(FactoryTable)
repeat
if not dontWait then
waitForRequestBudget()
end
success = pcall(dataStore.UpdateAsync, dataStore, key, function()
return {
SessionLock = dontLeave and os.time() or nil,
Money = moneyValue,
Tokens = TokenValue,
Levels = levelValue,
FactoryData = FactoryTable
}
end)
until success
The print(FactoryTable)
prints this:
I really have no idea what’s wrong, and would appreciate help!