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 would I structure a Data Store?

Asked by 3 years ago

I plan on saving customizable user items in a data store, but my problem is how would I structure it?

Lets say there there are 20 types of bikes the user can customize in 7 different category's (Wheels, color, handle bars ETC. ), would I make 20 different data stores with 5 tables in them? Or would I make 1 datastore and somehow cram all the info into a table?


Bike format:

       |--wheels (7 options to pick from)
       |--paint (7 options to pick from)

bike 1 --| bars (7 options to pick from)

There are 20 different types of bikes total. How would I save all that information. Multiple data stores?

1 answer

Log in to vote
Answered by 3 years ago

Since datastores can save tables, this is very easy.

local ds = game:GetService("DataStoreService"):GetDataStore("DataStoreName")
local defaultItems = { -- this will be what the player gets if they're new to the game
"AwesomeHat", -- idk some random item name
"CoolBeans", -- another random one
-- add more of the items you want
local data = {} -- where all the players data is stored for everyone in the server

local tab = ds:GetAsync(plr.userId)
if not tab then tab = defaultItems end -- if they're a new player set to the default table
local found = false

for i = 1,#data do -- makes it so multiple data's aren't stored in the data tab
if data[i][1] == plr.Name then
found = true

if found == false then


local tab = nil
for i = 1,#data do
if data[i][1] == plr.Name then
tab = data[i][2]

ds:SetAsync(plr.userId,tab) -- saves their data

Hopefully that helps a bit..

I dont think you understood the question. One bike can be customized in several ways. I want all 20 bikes to have all their features saved the way the player set them to. Orlando777 315 — 3y
That's what the tables for. It saves their features and can be loaded the next time it's needed... ObscureEntity 294 — 3y
I edited the question. I know what tables do. But technically speaking I would have to put a table in a table. Is it possible to just create multiple data stores? Orlando777 315 — 3y
if you want different bikes then you can just save other tables inside that table ObscureEntity 294 — 3y
View all comments (4 more)
local tab = { {"Bike1",{"Bikeattachment1","BikeAttachment2"}},{"Bike2",{"BikeAttachment1",BikeAttachment2}}} ObscureEntity 294 — 3y
Btw, that doesnt seem to work. I cant seem to access Bikeattachment1 or 2, it says its nil. Orlando777 315 — 3y
it would be: local tab = {Bike1 = {"Bikeattachment1","BikeAttachment2"},Bike2 = {"Bikeattachment1","BikeAttachment2"}} Orlando777 315 — 3y
you can't do that with datastores. You can't do things like Bike1 = hdsgkjasdhsd. To get the data it's like tab[1][1] to get bike attachment 1. ObscureEntity 294 — 3y

Answer this question