Need Help With A Tycoon Saver

  1. I need some help with making a Tycoon Saver

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

  3. 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?:thinking:

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

return module

7 Likes

Can you format your scripts to increase readability? Trying to decipher the scripts gave me a headache.

3 Likes

No not really sorry I am not the best at scripting model and part savers I am kind of just starting to learn.:sweat_smile:

2 Likes

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.

1 Like

as i tried to replicate the same thing,heres my feedback, you might need to add some changes to it to fit your needs

1 Like

As @luaVovert said, I’ve wrote a reply to his which is basically the same thing here…

All of the information is described in that post…

4 Likes

Thanks for that I will look into it and see if it works.:smile:

2 Likes

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”.

1 Like

Yes that is the type of tycoon I am making sorry if I was not clear about that

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…

2 Likes

I think you misunderstood what TheRobloxPlayer was saying,

format your code above like this

print("Formatted Code")

instead of this

print(“Non-Formatted Code”)

just put grave accent’s ``` at the top and bottom of your code to format it

2 Likes

image

1 Like

You should probably use datastore 2 I feel like it’s better in most aspects.

I have not really gone down that road of a datastore2 yet, but I would be glad to learn

2 Likes

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

1 Like

There is a bug with this because the tabel expected is nil

1 Like

Thx I definetly will look at this

Well check if it’s nil before doing that…

1 Like

sorry I meant the tabel got nil

What do you mean by that ?
The table contains nil values or is it not yet defined ?

1 Like