Need Help With A Tycoon Saver

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

Here is what it says " ServerScriptService.Tycoon Saver:24: bad argument #1 to ‘insert’ (table expected, got nil)"

Most likely you’re table hasn’t been declared yet and cannot be interpreted by the script.

Update the code… Should work now

What do you want me to update from the code? I tried your last one and it has a nil error, referring to the table not being declared yet, is there anything else you want to tell me?

I fixed that bug… From where I was declaring the variable - “InfoToSave” I forgot to declare it as a table…

Just by changing

local InfoToSave 

to

local InfoToSave = {}

That is the only bug I am aware of.

1 Like

yeah thanks I just realized that on my own

1 Like

I am still having trouble with my script, it will not load the tycoon up properly here is the script I am using:

ServerScript In ServerScriptService
local Models = game:GetService("Workspace"):WaitForChild("Chevy", "Wall1") -- Only Part Of The Items in The Tycoon

local datastore = game:GetService("DataStoreService"):GetDataStore("TycoonSave")

game.Players.PlayerAdded:Connect(function(plr)
	wait(1)
     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]
print("Tycoon Loaded")
             --Load Model
       end
    end
end)

game.Players.PlayerRemoving:Connect(function(plr)
      local Tycoon = workspace.VehicleDealershipTycoonKit.Factory
      local InfoToSave = {}
      for i,v in pairs(Tycoon.Models:GetChildren()) do
            table.insert(InfoToSave, v.Name)
      end
      datastore:SetAsync(plr.UserId, InfoToSave)
print("Tycoon Saved")
end)
1 Like

Noticed where I put --Load Model

I didn’t put in the code to actually load the tycoon into the model since its against the rules to give the complete script… Basically its just going through all of the models and cloning and parenting the models.

You also want to have all of the models grouped together into a single model for that system to work… If you know basic lua, Im sure you can convert that code to work with your needs. It was just an example on how exactly its done.

1 Like

oh sorry i just realized, I am dumb.:stuck_out_tongue_closed_eyes:

1 Like