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

Is there a way to save a Table to a DataStore?

Asked by 3 years ago
Edited 3 years ago

Unless they have changed down DataStores work in the last year, it is impossible to save a DataStore as far as I know. For example, doing something such as DataStore:SetAsync(Player.UserId,{UD,BD,PD}) Will just return an error, saying that this is an invalid type. Is there something that I am missing, or is it impossible to natively store a table in roblox? I've tried external methods, such as with trellos, however recent changes to how they work leaves this method with an insufficient bandwidth. Any hints or help with this would be very helpful.

Edit: Before anyone mentions strings/JSONs, yes, I am aware of this, however it also prevents me from saving strings.

0
"however it also prevents me from saving strings." Not sure what you mean by this, you should be able to save up to 4 million chars in a single datastore blowup999 659 — 3y
0
I think you should watch The dev kings tutrial on datastore, towards the end of the video he shows how to do it I THINK im not 100% sure spectsy 16 — 3y

1 answer

Log in to vote
1
Answered by 3 years ago
Edited 3 years ago

It is very possible to save DataStores, especially with tables. If there wasn't 80% of the games on Roblox right now would be broken. The method you showed above is correct...

DataStore:SetAsync(Player.UserId,{UD,BD,PD})

However, it depends on what UD, BD, and PD are. You can only save more primitive values such as Strings, Numbers, or Tables to name a few. It doesn't work for Instances such as parts or ValueObjects, and it won't save CFrames or Vector3s. For example...

local UD = 5
local BD = 10
local PD = 1

DataStore:SetAsync(Player.UserId,{UD,BD,PD}) -- Works

--

local UD = CFrame.new(0,0,0)
local BD = CFrame.new(0,5,0)
local PD = CFrame.new(5,0,0)

DataStore:SetAsync(Player.UserId,{UD,BD,PD}) -- Doesn't work

--

local UD = workspace.Baseplate
local BD = workspace.Player
local PD = workspace.Ball

DataStore:SetAsync(Player.UserId,{UD,BD,PD}) -- Doesn't work

You can make your tables more advanced too...

local saveEntry = 
{
    UD = 1,
    BD = 2,
    PD = 3,
}

DataStore:SetAsync(Player.UserId, saveEntry) -- Works

local data = DataStore:GetAsync(Player.UserId)
print(data.UD, data.BD, data.PD)

Note: In order to do any Datastore work in studio, make sure the Permission is enabled to let the place use API in studio.

0
Attempting this just returns an error telling me that Arrays aren't allowed in a datastore. realgolddog12 1 — 3y
0
PD was just foran example, but BD and UD are each Tables in of themselves. realgolddog12 1 — 3y
Ad

Answer this question