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

How would I properly save and retrieve tables from a DataStore?

Here are the Variables I assigned:

local ds = game:GetService("DataStoreService")
local ds1 = ds:GetDataStore("Vrank")
local ds2 = ds:GetDataStore("ARank")

local owner
local admin = {}
local votePerms = {}

This is what I used to retrieve all the data saving into that table:

local s, e = pcall(function()
	for i, v in ipairs(ds1:GetAsync("VoteStarters",votePerms)) do
		table.insert(votePerms, #votePerms+1, v)
	end
end)

Finally, the code that is supposed to insert and save new data into the table:

if args[2] then
	if game.Players:FindFirstChild(args[2]) then
		local newRank = game.Players:FindFirstChild(args[2]).UserId
		table.insert(votePerms, #votePerms+1, newRank)
		local s, e = pcall(function()
			ds1:SetAsync("VoteStarters",votePerms)
		end)
	end
end

Thank you for taking the time to read this!

1 answer

✓ Accepted answer

Use HttpService (Link 1)

This converts it into a string (Link 2)

game:GetService("HttpService").JSONEncode()

This converts it back into a table (Link 3)

game:GetService("HttpService").JSONDecode()

Link 1 https://developer.roblox.com/en-us/api-reference/class/HttpService


Link 2 https://developer.roblox.com/en-us/api-reference/function/HttpService/JSONEncode


Link 3 https://developer.roblox.com/en-us/api-reference/function/HttpService/JSONDecode


1 comment

0

Thank you!

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