Hi! I am Chris. I am currently working on a ticket system and I need some help…
I always use this module that makes it very simple and easy to create datastores. I would need only 1 line to use it, which didn’t involve any datastore complications. However, this module doesn’t allow tables as it only allows values. ( BoolValue, IntValue, etc etc. )
I need to make datastores with tables that would give the following info;
local ticketTable = {
["Reason"] = reason
["Date"] = date -- don't know how to get this, i'll probably make another thread about later
["Username"] = game.Players.LocalPlayer.Name
}
I personally have no experience with actual datastore scripting and I would always end up not trying as it seemed complicated. I usually get cut-off by the confusing :SetAsync.
How would I accomplish creating a datastore that’d save the above table?
Honestly genuinely when I do datastores I use a completely different method.
Before I go on about how I do it you may want to know:
local date = os.date("!*t")
Is an easy way to get date, then you just do date.day etc.
Secondly:
Two methods really that I can see to solving this in my opinion, obviously many more:
JSONEncode / JSONDecode as suggested by Goldy. JSON is good because its a robust encoding which you can also transmit to things like discord and even between languages. I recommend this if you don’t want to key down your data and instead just want to upload it back and forth.
Second method is key and table. In this you have a key (which may be the date or something you can extract or even a player specifically). If you want more information then just message back on this reply. The basic principle is your going to make a table which you then save with the key and table using something like DataStore:SetAsync(key,table) - wrap in a pcall just in case it doesn’t work. This one is more complicated but datastores aren’t exactly easy and this method hasn’t let me down yet.
There is no need to JSONEncode nor Decode. Writing to a Roblox DataStore already does that on the web end, and you end up making things more complicated for your self for no reason.
All you really need to do is save that table to a key with :SetAsync, such as "GlobalTickets". For a ticket system, I recommend you save an array of dictionaries, the dictionaries being the tickets. As stated above, it’s highly advised you wrap this in a pcall to avoid errors.
In an external database on a different website or through Roblox. Purely because :SetAsync() could be used in a class if you really wanted to. I use that for creating an actual mirror effect (not set async but I create my own custom :FUNCTION() statements).
I’ve been using the datastore that is given with AGF (Aero Game Framework).
If you’re using datastore 2, it’s a bit different.
But if you’re using what i’m using, or the regular DataStores on roblox then it’ be something like this.
Make a table on the server for all of the players’ datas.
Use :GetAsync(Player) to call the table
If they don’t have a save, use a DefaultTable for them.
And use :SetAsync(Player, Table) to set the table
Example on default table:
DefaultTable = {
Coins = 0;
Unlocks = {
};
Example on how to change a value:
local PlayerSaves = {}
if PlayerSaves[Player] then
PlayerSaves[Player].Coins = 100;
else
if Data:GetAsync(Player) then
PlayerSaves[Player] = Data:GetAsync(Player)
PlayerSaves[Player].Coins = 100;
else
PlayerSaves[Player] = DefaultTable
PlayerSaves[Player].Coins = 100;
end
end