I am creating a big tycoon game and I need a saver could anyone help?

I have looked on the internet for some answers but I could not find any

I have tried to use a module script and server script to save the Tycoon, but it does not load properly
here are the scripts could anyone help?

Server script:

local ds = game:GetService(â€śDataStoreServiceâ€ť):GetDataStore(â€śCodesOtakuTutorialâ€ť)

local sl = require(game.ServerScriptService.SL)

local target = game.Workspace[â€śFactoryâ€ť]

wait(5)

ds:SetAsync(0, sl.ModelToArray(target))

target:Destroy()

wait(5)

local loadedArray = ds:GetAsync(0)

sl.ArrayToModel(loadedArray, game.Workspace)

Module script:

local module = {}

function module.PartToArray(part)
local result = {}
result[#result+1] = part.BrickColor.Name
result[#result+1] = part.Material.Value
result[#result+1] = part.Reflectance
result[#result+1] = part.Transparency
result[#result+1] = part.Name
result[#result+1] = part.Orientation.X
result[#result+1] = part.Orientation.Y
result[#result+1] = part.Orientation.Z
result[#result+1] = part.Position.X
result[#result+1] = part.Position.Y
result[#result+1] = part.Position.Z
result[#result+1] = part.Anchored
result[#result+1] = part.CanCollide
result[#result+1] = part.Size.X
result[#result+1] = part.Size.Y
result[#result+1] = part.Size.Z
return result
end
function module.ArrayToPart(array, parent)
local part = Instance.new(â€śPartâ€ť)
part.BrickColor = BrickColor.new(array[1])
print(array[1])
part.Material = array[2]
part.Reflectance = array[3]
part.Transparency = array[4]
part.Name = array[5]
part.Orientation = Vector3.new(array[6],array[7],array[8])
part.Position = Vector3.new(array[9],array[10],array[11])
part.Anchored = array[12]
part.CanCollide = array[13]
part.Size = Vector3.new(array[14],array[15],array[16])
if parent then
part.Parent = parent
end
return part
end
function module.ModelToArray(model)
local result = {model.Name}
for count,child in pairs(model:GetChildren()) do
if child:IsA(â€śBasePartâ€ť) then
result[#result+1] = module.PartToArray(child)
end
end
return result
end
function module.ArrayToModel(array, parent)
local model = Instance.new(â€śModelâ€ť)
model.Name = array[1]
for count,element in pairs(array) do
if count > 1 then
module.ArrayToPart(element, model)
end
end
if parent then
model.Parent = parent
end
return model
end

Just use datastores and come up with a data system that works for you and when a player joins itâ€™ll read the data and load the tycoon pieces they should own.

That method is a bit faulty as that method is tailored towards gameâ€™s like Miners Haven. I assume OP is referring to a more traditional tycoon with â€śbuttonsâ€ť.

You can still use the same base for itâ€¦ Just with different aspects of itâ€¦

So lets say each button has a model in ServerStorage that it brings on once you buy itâ€¦

local Models = game:GetService("ServerStorage"):WaitForChild("Models") -- Replace with correct path
local datastore = game:GetService("DataStoreService"):GetDataStore("TycoonSave")
game.Players.PlayerAdded:Connect(function(plr)
local good, info = pcall(function()
return datastore:GetAsync(plr.UserId)
end)
if good then
for i,v in pairs(info) do
local model = Models[v]
--Load Model
end
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local Tycoon = --Path to their tycoon
local InfoToSave = {}
for i,v in pairs(Tycoon.Models:GetChildren()) do
table.insert(InfoToSave, v.Name)
end
datastore:SetAsync(plr.UserId, InfoToSave)
end)

This is off the top of my head so their may be bugsâ€¦

This is mostly based off of assumptionsâ€¦ This will work if there is a model in the Tycoon called Models that contains each separate componentâ€¦

If you have 0 scripting experience, I highly down youâ€™ll be able to take this code and get it workingâ€¦ But after all, this category is not for free scriptsâ€¦ It should give you a place to startâ€¦

Itâ€™s way simpler than the original datastore and manages saving without overflowing your request there as never been a data loss with it, I suggest you check this to learn further I really recommend using it: How to use DataStore2 - Data Store caching and data loss prevention