Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Datastoring a custom Inventory?

Asked by 5 years ago

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

0
Using JSON, You can literally convert table to string and then save that string and then return back to a table!! Crazy right? mixgingengerina10 223 — 5y
0
why would i want to use JSON LordOfWatermelons 27 — 5y

1 answer

Log in to vote
1
Answered by
zblox164 531 Moderation Voter
5 years ago

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!

Ad

Answer this question