Hey guys! So I was having a problem with Datastores in creating my loadout saving mechanic in my game, and it says I can’t use Arrays in Datastores. I’m not sure how I should go about putting the array into the datastore. Anyone have ideas? My code that I have is below in case you need to know what I’m doing
local DatastoreService = game:GetService("DataStoreService")
local Remote = game.ReplicatedStorage.Hotbar
local Hotbar = DatastoreService:GetDataStore("Hotbar")
Remote.OnServerEvent:Connect(function(p,a,b,c,d,e)
Hotbar:SetAsync(p.UserId, {a,b,c,d,e})
end)
Okay so for context, I’m making a tower defense game and I’m trying to implement allowing you to customize what you start the game with (towers to play with) and each slot in the inventory has a value, (theres 5 slots) and they all have a value that simply just says the name of the tower.
JSON encryption is not a necessity for data storage. Not that it is useless, but you can store table types either way.
There is a misunderstanding of tables in this thread. Dictionaries are an extension of arrays. You can store a dictionary in a DataStore, and likewise you can store an array in a DataStore at less cost. Our games do it consistently with no external modules.
Oh, I’ve experienced an issue in the past where my code printed an error although I was able to do it before, where it said “Cannot store Dictionary in DataStore” and my old and newer script were relatively the same, utilizing only numbers + strings. No instances because you cannot save those to a DataStore.
The minute I switched over to HttpService:JSONEncode() the error immediately went away so I assumed it was the mix of numbers and such.
I’m not an expert at anything under the hood of Luau. You will see certain improvements from encryption likely because I imagine less bytes are needed.
Ages ago I would write my Data with encryption, now my primary use-cases for JSON involve actual Http requests.