I’m creating a inventory storing system for my game and need to store a table. I’m using basically the same script I would if I were storing strings or numbers, but I’m getting a strange error. The error I got will be down below, I’m not exactly sure what it means. I’ll also be putting an example of what I’m doing below. Yes I have searched for things related to this, but none of them worked for me.
local t = {["Clockwork Shades"] = {Name = "Clockwork Shades", Rarity = "Rare"}}
game.Players.PlayerAdded:Connect(function(player)
local key = string.format("Player_%d", player.UserId)
local data = game.DataStoreService:GetDataStore("stuff"):GetAsync(key) or t
end)
game.Players.PlayerRemoving:Connect(function(player)
local key = string.format("Player_%d", player.UserId)
game.DataStoreService:GetDataStore("stuff"):SetAsync(key, t)
end)
Are you allowed to store arrays in data stores? That error sounds a bit inaccurate. I feel like it should say they only accept valid UTF-8 strings. Note: I’ve never used data stores before.
I’d assume behind the scenes when you supply a dictionary, it automatically knows what to do. It grabs the key and uses that as the key and then the value and uses that as a value for each key/value pair. If you try to save t, then it will grab the key “Clockwork Shades” and then grab the value which is an array. This would explain the error.