I have made a custom inventory with dragging and such and is working quite nicely, however, how would i go about datastoring it.
How would i datastore:
• the name of the items the player has?
• Where the item goes in the inventory GUI (Slot1 or 2 or 3 etc.) ?
• The stack(quantity) of the item ?
• Whether or not the item was equipped or not so next time the player joins they are still equipping it?
Keep in mind this is not a request and that im just trying to get the concept and idea of how to go about doing this and not asking for actual code or anything like that, however, feel free to use little code snippets to get the point across.
Thanks! :D
You could convert your data to a string then save that. Then when the player returns to the game you can load the string and convert it back to the original stats (table). This is what is known as serialization. Taking an object converting it to a string then reconstructing it back when needed (deserialization). Here is an example:
local HttpService = game:GetService("HttpService") local Data = {"Simple Text", 8, true, false, nil, "More"} -- Simple data SerializedData = HttpService:JSONEncode(Data) -- Convert to string game.Players.PlayerAdded:Connect(function() -- De serialize local DeSerializedData = HttpService(SerializedData) -- return to table end)
Now your data will be much more complex as you will need to store each inventory slot, name, stack, and equiped or not equiped. Use table.insert()
to put your data into the table.
Convert, and save when player leaves Convert back and load when player joins back again
This is the concept. Hope this helps you understand the process!