Saving player made game data

Hello, I want to be able to save and load data like a game save.
The problem is, there is no set data like a obby or tycoon. All the elements that I need to save are changed by the player. (ex. Roller-coaster Tycoon, Store Tycoon)

The only thing that came to my mind is either, save every item the player has and where its located.
(I just need a general Idea on how to create this)
Edit: This is not like the examples above its a PC building type game so all the parts within the a PC (CPU, GPU) Need to be stored somehow I don’t know how to in a efficient way.

1 Like

This is probably the best topic so far. You can get the CFrame of where it’s located, relative to the base of the tycoon. I would suggest storing these in tables.

You should use a table for this, then save it to a datastore.

local ItemsTable = {
    ["PlayerName"] = {
        {
            ["ItemName"] = "RealItemName",
            ["Location"] = "RealLocation"
        }
    }
}

I thought of this but when I would research about it people say that datastore does not support dictionary’s.

In that case, you could use HttpService to JSONEncode it, then save it as a string. Once you want to fetch the data, get the string, and use HttpService to JSONDecode it.

Not true, you can store a dictionary in a datastore.

That was quite a while ago. Data stores have been compatible with dictionaries for a good amount of time

Ah, I must of read a very old post then.

Try this script and note that this will be in serverscriptservice.

local DataStoreService
game:GetService(“DataStoreService”)
local playerData = DataStoreService:GetDataStore(“PlayerData”)

local function onPlayerJoin(player) – Runs when players join
local leaderstats = Instance.new(“Folder”) --Sets up leaderstats folder
leaderstats.Name = “leaderstats”
leaderstats.Parent = player

local gold = Instance.new("IntValue") --Sets up value for leaderstats
gold.Name = "Gold"
gold.Parent = leaderstats

local playerUserId = "Player_" .. player.UserId  --Gets player ID
local data = playerData:GetAsync(playerUserId)  --Checks if player has stored data
if data then
    -- Data exists for this player
    gold.Value = data
else
    -- Data store is working, but no current data for this player
    gold.Value = 0
end

end

local function onPlayerExit(player) --Runs when players exit

local success, err = pcall(function()
    local playerUserId = "Player_" .. player.UserId
    playerData:SetAsync(playerUserId, player.leaderstats.Gold.Value) --Saves player data
end)

if not success then
    warn('Could not save data!')
end

end

game.Players.PlayerAdded:Connect(onPlayerJoin)
game.Players.PlayerRemoving:Connect(onPlayerExit)