The script im using below should work, Im just not sure if I should put the tycoon objects Ids into the save table, or how to put the tycoon purchases into the save tables at all.

``
local DataStoreService= game:GetService('DataStoreService'):GetDataStore("PretendCodeIsHere")
local RunService = game:GetService("RunService")
local db = 3
function SaveTableFunc(player)
    local SaveTable = { 
    }
    return SaveTable
end
game.Players.PlayerAdded:connect(function(player) 
    repeat wait() until player.Character
    repeat wait() until script:FindFirstChild("stats")
  local save1 = script.stats:Clone()
    save1.Parent = player
    local stats = player.stats
    local save = SaveTableFunc(player)
    local playerkey = "player-"..player.userId
    local SaveFiles = DataStoreService:GetAsync(playerkey)
    function dataInput(player, save)
          print("Got saved data for "..player.Name)
    end
    local Passed, Error = pcall(function() 
            if SaveFiles == nil then
                print(player.Name.." has no save data yet")
            else
        dataInput(player, save)
            end
    end)
    if Error then
        print("***ERROR GETTING SAVE FILE FOR "..player.Name)
        local attempts = 0
        while wait(db) do
            local retries = attempts + 1
            attempts = retries
            local pass,err = pcall(function()
            if SaveFiles == nil then
                print(player.Name.." has no save data yet")
        else
        dataInput(player, save)
            end
      end)
            if pass or attempts == 5 then break end
        end
    end
end)
 
function SaveData(player)
    local Success,Error = pcall(function()
        local playerkey = "player-"..player.userId
        local save = SaveTableFunc(player)
        DataStoreService:SetAsync(playerkey,save)
        print("Saved data for "..player.Name)
    end)
    if Error then
        print("***ERROR SAVING DATA FOR "..player.Name)
        local attempts = 0
        while wait (db) do
            local retries = attempts + 1
            attempts = retries
            local pass,fail = pcall(function()
                local playerkey = "player-"..player.userId
                local data = SaveData(player)
                DataStoreService:SetAsync(playerkey,save)
                print("Successfully saved data for "..player.Name)

            end)

            if pass or attempts == 10 then break end

        end

    end
end
 
game.Players.PlayerRemoving:Connect(SaveData)
 
game:BindToClose(function() 
    if RunService:IsStudio() then return end
    local Players = game:GetService("Players")
    for _,player in pairs(Players:GetPlayers()) do
        SaveData(player)
        print("Saved data for "..player.Name.." on shutdown.")
    end
end)``

9 comments

0

please fix your lua brackets

0

there sorry about that I didnt see how ugly it looked lol

0

Thats a really good question. The way i'd probably do it is to just have a bool value and mark them true upon purchase. But depending on if your tycoon is a cookie cutter or custom, you need to make the purchase handler work with the datastore.

0

If you structure them by name, it allows you to change things down the line easier than a linear 1,2,3 system. Especially if your tycoon allows you to build different paths.

0

So you’re saying that inside of the save table I should just write the name of the purchase and then put a bool value inside of that script?

0

More or less. The script you're using youd create a bool, name it whatever "OwnerDoor" or the items name, make sure its false, then have the same thing in the save table. You can see an example on the other question i linked.

0

I've not personally done a tycoon save system before but, the hard part will be making it so that whenever you purchase the item, it can correctly reference the corresponding bool.

0

Ok,I really appreciate the help,I’ll try that as soon as I can

0

Let me know if you need anything else. If you need some inspiration i believe Zeds tycoon kit has a built in save system, so you could check that out for ideas.