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

How does one datastore a table?

Asked by
Mr_Unlucky 1085 Moderation Voter
4 years ago
Edited 4 years 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!

2
use HttpService to convert the table to JSON and then upload that to the datastore the8bitdude11 358 — 4y
0
Many people have been using DataStore2 by Kampfkarren and it is makes saving so much easier. Definitely check it out: https://devforum.roblox.com/t/how-to-use-datastore2-data-store-caching-and-data-loss-prevention/136317 PhantomVisual 992 — 4y

1 answer

Log in to vote
2
Answered by 4 years ago
Edited 4 years 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

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

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

1
Wow, I was not expecting an answer like this! This is really good! Thanks dude Mr_Unlucky 1085 — 4y
0
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 1784 — 4y
Ad

Answer this question