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

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

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.

2 comments

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

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

1 answer

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.

2 comments

0

Attempting this just returns an error telling me that Arrays aren't allowed in a datastore.

0

PD was just foran example, but BD and UD are each Tables in of themselves.

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