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

Cannot store Array in DataStore?

The question title is what the output id reading. "Cannot store Array in DataStore". How can I fix this?

It was working so far with Exp, Rank, and RankVal, but now after adding RunVal, WalkVal, and Cash it does not work.

Here's my code so far:

local dss = game:GetService("DataStoreService"):GetDataStore("Data") -- Give it a name.

game.Players.PlayerAdded:connect(function(plr)

    local UniqueKey = 'id-'..plr.UserId



    local stats = Instance.new("Folder", plr)
    stats.Name = "leaderstats"

    local rank = Instance.new("StringValue", stats)
    rank.Name = "Rank" 
    rank.Value = "Newbie"

    local val = Instance.new("IntValue", stats)
    val.Name = "RankVal"
    val.Value = 1

    local exp1 = Instance.new("IntValue", stats)
    exp1.Name = "Exp"
    exp1.Value = 0

	local run = Instance.new("IntValue", plr)
	run.Name = "RunVal"
	run.Value = 50
	
	local walk = Instance.new("IntValue", plr)
	walk.Name = "WalkVal"
	walk.Value = 35
	
	local cash = Instance.new("IntValue", stats)
	cash.Name = "Cash"
	cash.Value = 0



    local GetSaved = dss:GetAsync(UniqueKey)
    if GetSaved then
	    rank.Value = GetSaved[1]
	    val.Value = GetSaved[2]
	    exp1.Value = GetSaved[3]
		run.Value = GetSaved[4]
		walk.Value = GetSaved[5]
		cash.Value = GetSaved[6]
    else
        local toSave = {rank.Value, val.Value, exp1.Value, run.Value, walk.Value, cash.Value}
        dss:SetAsync(UniqueKey, toSave)
    end
	game.ReplicatedStorage.Event:FireAllClients(plr.Name, val.Value);
	val.Changed:connect(function()
		game.ReplicatedStorage.Event:FireAllClients(plr.Name, val.Value);
	end)
end)

game.Players.PlayerRemoving:connect(function(plr)

local UniqueKey = 'id-'..plr.UserId
local d = plr.leaderstats
local savetable = {d.Rank.Value, d.RankVal.Value, d.Exp.Value, plr.RunVal, plr.WalkVal, d.Cash}   -- A table to hold/save all the values.

dss:SetAsync(UniqueKey,savetable)
end)

1 answer

✓ Accepted answer

You error means that there is something in the array you are trying to save that is not compatible with DataStores. In your case, you added plr.RunVal, plr.WalkVal, and d.Cash which are all Roblox Instances. You want to save the values that are stored in those instances.

Fix for line 60:

local savetable = {
	d.Rank.Value,
	d.RankVal.Value,
	d.Exp.Value,
	plr.RunVal.Value,	-- Added `.Value`
	plr.WalkVal.Value,	-- Added `.Value`
	d.Cash.Value		-- Added `.Value`
}

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