New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Still have questions? Join our Discord server and get real time help.
Log in to vote

How does one datastore a table?

Asked by
Mr_Unlucky 1064 Moderation Voter
3 months ago
Edited 3 months ago

This isn't a request question, don't worry.

I'm currently working on a combat game in which I want to have an inventory system for weapons. Games such as Phantom Forces and Murder Mystery 2 have this feature, where they can data store the player's skins/weapons at ease. I've seen numerous posts on the DevForum and Questions here about this, however none of them make total sense to me.

If anyone has an idea, please answer!

use HttpService to convert the table to JSON and then upload that to the datastore the8bitdude11 297 — 3mo
Many people have been using DataStore2 by Kampfkarren and it is makes saving so much easier. Definitely check it out: PhantomVisual 742 — 3mo

1 answer

Log in to vote
Answered by 3 months ago
Edited 3 months ago

The proper way to convey your request is more along the lines on "How to save a table". The only way to do so on Roblox, excluding HttpService, would be through DataStores.

Let us break down what we are trying to do and how first. The simplest way to explain it is how to save a table use DataStores. Although, you specifically discuss an inventory, showing we need to save information on a player-to-player basis.

local DataStore = game:GetService("DataStoreService")
local InventoryData = DataStore:GetDataStore("Inventory") -- This is where related data will be found

    if not InventoryData:GetAsync(tostring(Plr.UserId)) then -- Does a previous save exist?
        InventoryData:SetAsync(tostring(Plr.UserId), {}) -- Save a table to their save

Please keep in mind, all the above code does (assuming it works, did not use studio to type or test) is save a table to the player under a key, key being how you get their unique data, which is their userid. We use a userid because it will never change for their account, unlike name which can be changed.

If there are issues or questions, feel free to comment below!

Almost forgot, here is a great link on how to use DataStores

Wow, I was not expecting an answer like this! This is really good! Thanks dude Mr_Unlucky 1064 — 3mo
No problem. Answers usually depend how everyone feels lol. Sometimes you get the full product and other times you just get told what to probably do alphawolvess 1699 — 3mo

Answer this question