Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to use datastores for inventory saving?

In my game, I want there to be inventory saving. Say if the player bought clothes, it would save what clothes they have on, and load them back in when they rejoined. I don't know much about datastores, and my current attempts have failed. Does anyone know a bit more about datastores that could help me with this?

3 answers

I personally would recommend that you store a string of all names in a table and save that, then when they hop on the game again, you iterate through that table and where you keep clothes. If there is a match, clone it to them and whatever you have to do to make them wear it. Hope that gets you in the right direction!

Use this code to get their inventory:

game.Players.PlayerRemoving:Connect(function(player)
	local char = player.Character

	for i,v in pairs (player.Backpack:GetChildren()) do
		table.insert(table,#table + 1,v)
	end

	for i,v in pairs (char:GetChildren()) do
		if v:IsA("Tool") then
			table.insert(table,#table + 1,v)
			break
		end
	end

	--Data store code
end)

Then DataStore it all. Hope this helped!

This discussion is preserved as it was. New answers, comments, and votes are closed.