Is it possible to make a database for a Roblox game?

I forgot to say that the value i was gonna store was a table, and that didn’t work.

Just found out how to store tables onto datastore.

So you just JSONEncode the table you want and just save it as normal.
when retrieving the data from the datastore you just JSONDecode it and it will become a table again.

I’m pretty sure you don’t have to encode and decode, it’s done automatically. The error might be caused by something else like for example trying to store an Instance to a datastore.

1 Like

Yep it was and still is, I can’t store instances so I can’t do the database thing, it won’t work for my purpose

That’s not true. The issue with instances is that there is not a clearly defined way to save them. However if you can pinpoint down the exact information of each instance that you wish to save, you can save it in the form of a dictionary(where a key is for example a property and the value is that property value).

Ik that but it’s too much instances to save the information for that includes scripts and models so I think it’s not viable

if your value is in a table try and convert it into a json array then convert it back to a lua table to read the contents the other place

Game1:

-- Get the datastore service and store it in a local varible.
local dataStoreService = game:getService('DataStoreService')

-- Get HttpService so we can use its Json conversion calls
local httpService = game:GetService('HttpService')

-- Create or read if already created, the "MyCars" datastore
local cars = dataStoreService:GetDataStore('MyCars')
cars:SetAsync('carName', httpService:JSONEncode(yourCarLuaTable)) -- Encode into a json array

Game2:

-- Get the datastore service and store it in a local varible.
local dataStoreService = game:getService('DataStoreService')

-- Get HttpService so we can use its Json conversion calls
local httpService = game:GetService('HttpService')

-- read "MyCars" datastore
local cars = dataStoreService:GetDataStore('MyCars')
print(httpService:JSONDecode(cars:GetAsync('carName'))) -- Decode json array into lua table and print it

Hope this helps!

1 Like

I could use that but I need also the car’s model that contains too many instances or do the serializing thing

ok, im going to do some researching. So the problem is that you are trying to store instances in datastore, im pritty sure storing instances in datastore is impossible unless you convert its properties into a 3d table.

1 Like

this devforum post may help:
How do i save an instance with Datastore Service? - Help and Feedback / Scripting Support - Developer Forum | Roblox

1 Like

I already knew about that post but I can’t use serialization because it’s too many instances and scripts to serialize.

so, is there a physical limit in place stopping you from using this method or do you just want to say no because you think its inefficient?

A physicial limit, because you can’t redo a script

so what exactly do you mean by you cant redo a script, you can put it in startergui and it will reload the script when the player gets respawned

You could instead save either the cars as models, and save the AssetId in a datastore. You can then insert them in game using InsertService:LoadAsset()

You could also use Packages, maybe with this method, and :LoadAsset?
You might not need to save anything in a datastore if you use packages, it seems like you might be able to put every car in a single package? Well you could do the same with models
I’m not too familiar with packages

1 Like

The problem is that I need to sync the car’s tune script + the a-chassis script and a bunch more with other places on the same game

didnt know that existed if im going to be honest!

1 Like

That could be used b u t I need it to be dynamically updated, if I use this method I need to edit every car name code on every place, and I don’t want to do that because it’s too much time consuming and the fact that the game could have more than 30 places on the future doesn’t help

You can update the model or package, and when the games will retrieve the model/package, they will get the lastest version

You can also store the information regarding the cars inside the model/package, and have a system in place that iterates over all the cars in the model/package, and does what needs to be done. Heck, you can even have scripts inside the model/package

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.