Saving a shop/inventory

I’m making a shop and when people purchase from it, it shows up into their inventory (a different GUI).

How would I go about saving their whole inventory (a GUI not backpack) so that when they play the game again it loads it all.

I’m familiar with saving a few values of data.

4 Likes

You can’t save GUI’s, so what you need to do is save the values of the items themselves in your inventory. Something along the lines of this:

DataStore:SetAsync("Inventory", {["Item1"] = "aTool"})

I would give a better example but I’m only familiar with my own data storing service.

This isn’t what I meant, I know I can’t save GUI’s. What I wanted to do is have values in a folder named, be saved when a player leaves. And when the player joins again I want it to load those values and get the gui/frame from serverstorage by using the value name.

local ServerStorage = game:GetService("ServerStorage")

for _, value in ipairs(ServerStorage:GetChildren()) do
	if inventory[value.Name] then
		local GuiClone = value:Clone()
		
		-- set the clone's parent, a basic example
	end 
end

Thats not what I meant either.


for _, value in ipairs(folder:GetChildren()) do 
     datakey:SetAsync(plr.UserId..value.Name)
end)

Would this work? if so how would I load it back in.

Uhh…Can you explain a little more then ?

Nope, use tables and insert the values in a table and save it in the datastore.

Example code -

local table = {}
for _, value in ipairs(folder:GetChildren()) do 
     table.insert(value.Value, table)
end)

DataStore:SetAsync(plr.UserId, table)

If you wonder why I used value.Value is because I assumed that you used a folder so you have like an IntValue or somewhat like that.

Alright, this makes more sense. Thanks.

For loading it back in when the player joins would I make a loop, finding the value name in a folder and cloning it? For example I had like a accessory.

Nope, see you saved a table, so loop through the table and set the values equal to the value you setted in the table.

Also, I wanna ask that your values are pre-added and you need to set the value of that values ? I mean like as you save leaderstats, you have an IntValue that you know is gonna be added, so you save the value and load that value in the IntValue.

I was thinking of pre-loading a folder with like everything you can purchase/achieve + importing a folder with everything you own and cloning it.

This sounds quite confusing I’m trying to think of a way to make it sound not confusing.

Hmmm…Ok, so you need to just save the values in the table and load the values from the table and clone to the folder.

Basically there will be a folder with:

All skins wraps, anything possible to buy.

When a player purchases something it creates a value named by that thing they purchased (this value will be put into that folder). (The thing they purchased will show up on an equip gui or some sort)

When the player leaves it saves that whole folder with the values.

When they join back it loads the data, creates values and puts it into that folder. Then it will find all the items that the player has purchased using the values and puts it onto the gui using :clone (there will be a main folder with all of the item guis.)

Ok, so I was right. Add the value to the folder (String or IntValue because they are objects) when someone purchased something and add it to a table, then if the player leaves, save the table, and after the player joins, loops through the table and insert a new value using Instance.new and the parent should be the folder

1 Like

Alright, thanks a lot. This will help a ton

1 Like

I kind of read in the documentation that you can create your own DataStore and you can use this to save each thing in a specific GUI slot like this:

local dss = game:GetService("DataStore")
local 1slot = dss:GetDataStore("FirstSlotDataStore")
-- and further

-- when players leaving:

1slot:SetAsync(Player.UserId, "ItemName")
2slot:SetAsync(Player.UserId, "ItemName")

-- and further

Im not sure exactly about this information, I advise you to check the documentation for reliability

You can’t save many values indivisually, save it using tables and saving it in multiple datastore isn’t the way, he said you can buy many things, so we don’t know how much datastores to make and even if it’s possible, it’ll be too much complicated.

1 Like

Um, I just advised how to do it
but I ll take it into account when developing

1 Like

Yeah, np, advising is good, I wasn’t criticizing. I just gave a tip to remember and I hope it helps.

1 Like