How to save items in your inventory

I searched up numerous of topics to see how to do this but I’m trying to make a egg simulator where you collect eggs and they save in your inventory

Btw Here is what my inv looks like:help

I also want it so the server saves the script and it sends the info to the client

1 Like

i think the solution will be using datastore2, you have make a table with the eggs names and make them a boolValue , i did something like this with souls , and then you make a function, when player touch/get an egg it will make “the egg name” = true, and if it true then it show on your inventory

this video helped me to make datastore2

before you use the datastore you have to get this free model

i hope it helped…

The thing is the egg isnt physical its digital like ui

This is a possible solution, but it seems like that method saves a lot of unnecessary data (all of the items are saved/loaded even if unowned) unless datastore2 does something behind the scenes that I don’t know about.

I think a more efficient solution is to save the inventory as a table of strings, that way you only actually save items that the player owns. (It also means you don’t have to manually add boolean table entries in the script)

1 Like

it doesn’t matter… how you want to players to get the egg? if it’s by pressing a button then you can do instead of touched function do buttonpressed function

I ran into this issue while developing one of my projects. I corrected it by storing it as a table(lists work too) on the server. This is where a generic handler comes into play. Each interval or each time the player dies, I have a remote event that pushes the server to reload my inventory or make changes if needed. In my sole opinion, datastores are very sensitive to everything. They’re like the DISH network of tv providers. Sometimes they work flawlessly, and other times a minor(non-threatening) issue arises.

1 Like

Thats what am asking how would i do that i now how to add a table i cant save it correctly thats all im asking how do i save it if i were savinga ui or something.

local saveTable = {}
local player = game.Players.LocalPlayer

for _,item in next, player.Backpack:GetChildren() do
   table.insert(saveTable, item.Name)

Then you would save that table. When loading it, you would loop through the table and clone the item based on the name of the index.

1 Like

can i clone a ui? like if i saved a players ui can i clone that when they load in using this method?

1 Like

You can clone UI’s. I usually clone like buttons for example. I would not recommend cloning a players UI, instead save the stuff in the players UI and then clone stuff based on the names and properties.

Yea that what was i was looking for cloning UI’s because instead of making a egg tool i wanted to make it virtual to save me the time

You know what lol imma save there ui just to keep it simple instead of saving the items name but do you know anyway i would do that from your perspective cuz im planning to use my method datastore3 where instead of saving the item by its name ill just save the host ui data so basically my method is to save the main object or whatever im trying to save

1 Like

Eyo, that video ontop Is what I created but it does contain some minor/major issues that I want to account if do plan on using it:

Move that point giver thing out of the PlayerAdded function (We Dont want to give everybody points if you click it now do you?)

Another thing, you can save it with using only 1 key, yes thats right.

The function that updates the stats within should look somewhat like this:

World.Value = DS2(MK, plr):Get(UpdatedValue)["Stats"]["World"]

As you can see, it changes the “World” (Point/Value) to equal to whatever the player’s data has.

DS2(MK, plr):OnUpdate(UpdateAllStats)

That is to update the data, as you can see, it uses only 1 key to do this. (MK is the key) (DS2 Is DataStore2)

Heres an example of changing and setting the data:

local LocalPlayerData = DS2(MK, LocalPlayer):Get(SetDataTable())
LocalPlayerData["Achievements"]["DidIntro"] = true
DS2(MK, LocalPlayer):Set(LocalPlayerData)
DS2(MK, LocalPlayer):Save()

As you can see, DS2 is Datastore2 of course, it sets the key from when you changed the value to true from the table.

Thats all I have to say :+1: good luck developing.