Hey there! I'm having a bit of trouble dealing with DataStores. While trying to initially set the values for a player, I am given the error: Array is not allowed in DataStore. I was wondering what I was doing wrong and if someone could inform me in which path to take to correct this. Thank you!
This is a regular script located in ServerScriptService if that is of any use.
local dataStore = game:GetService("DataStoreService"):GetDataStore("GeneralStatsTest")
game.Players.PlayerAdded:connect(function(player)
local key = "playerTest-"..player.userId
local kills = Instance.new("IntValue", player)
kills.Name = "Kills"
local deaths = Instance.new("IntValue", player)
deaths.Name = "Deaths"
deaths.Value = 1
local credits = Instance.new("IntValue", player)
credits.Name = "Credits"
local getSaved = dataStore:GetAsync(key)
if getSaved then
kills.Value = getSaved[1]
deaths.Value = getSaved[2]
credits.Value = getSaved[3]
else
local valuesForSaving = {kills.Value, deaths.Value, credits.Value}
dataStore:SetAsync(key,valuesForSaving)
end
end)

2 comments
Arrays can't be saved in DataStores.
Exactly. Try reading the wiki and or actually writing code and you may be surprised as to what an Array is.