Saving Inventory with DataStore2

Hi all,

I am currently working on a very simple accessory shop for my sport game.

Since I recently got uncurable PTSD from Roblox’s DataStore, I now rely 100% on DataStore2.

So, how I proceed to save the player’s inventory is simple. Here inventoryFolder refers to a Folder located inside the player instance and its inside is bunch of string values that share the same name as the item stored inside ServerStorage. When you make a purchase, this ChildAdded event fires.

inventoryFolder.ChildAdded:Connect(function(v)
		local playersVisors = {}
		for _,v in pairs(inventoryFolder:GetChildren()) do
			table.insert(playersVisors, v.Name)
		end
		print(playersVisors)
		dataVisors:Set(playersVisors)
	end)

When I print the table, all the values are as they should be except for the last one. The last one shows up as “Value” and, thus failing to load when the player rejoins as there is no item called “Value” inside the serverstorage. I’m guessing that is because as soon as the stringValue is created inside the folder, the event fires before the purchase script changes its name.

What I think would work is adding some sort of wait() inside the event but this is what I want to avoid. My question is the following: Is there any better alternative to solve this problem

Thanks in advance!

the solution was pretty easy LOL

all i had to do is move the line where the stringValue’s parent is set to the folder right under the line where the same instance is named.

every day i suffer a severe loss of braincells. this is the life of a roblox developer.

1 Like