Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Array is not allowed in DataStore?

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 answers

✓ Accepted answer

I'm guessing these are the lines that are erroring.

        local valuesForSaving = {kills.Value, deaths.Value, credits.Value}
        dataStore:SetAsync(key,valuesForSaving)

The first line is what is causing your troubles. In order to format your data for saving, you would want it to read something like

        local valuesForSaving = {Kills=kills.Value, Deaths=deaths.Value, Credits=credits.Value}

When you want to read the values, you would use this:

kills.Value=getSaved.Kills

2 comments

0

Arrays can't be saved in DataStores.

0

Exactly. Try reading the wiki and or actually writing code and you may be surprised as to what an Array is.

This discussion is preserved as it was. New answers, comments, and votes are closed.