Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Cannot store Array in DataStore?

Asked by 6 years ago

I'm trying to make character customization and I'm about done with it but... I need to save the information the player has selected into a DataStore.

This is my code and the error I'm getting is "Cannot store Array in DataStore". I've tried using a for loop to cycle through Value but then it gave me an error saying "Cannot store int in DataStore". I've also tried to cycle through "UpdateStats" but then I remembered that it was a function and not a table. So my question is: How do I fix the error and how does it work so I won't make the same mistake later?

local rep = game:GetService("ReplicatedStorage")
local CharInfo = rep.CharInfo
local DDS = game:GetService("DataStoreService")
local CharInfoDDS = DDS:GetDataStore("CharactInfo")




CharInfo.OnServerEvent:Connect(function(player)
    print("This works lol")
    --Infomation
local BodyColors = workspace.Character.Head.BrickColor
local PrimaryHair = workspace.Character:WaitForChild("PrimaryHair").HairNum.Value
local PriColorHair = workspace.Character:WaitForChild("PrimaryHair").Handle.BrickColor
local PriNeon = workspace.Character:WaitForChild("PrimaryHair").Handle.Material
local SecondaryHair = workspace.Character:WaitForChild("SecondaryHair").HairNum.Value
local SecColorHair = workspace.Character:WaitForChild("SecondaryHair").Handle.BrickColor
local SecNeon = workspace.Character:WaitForChild("SecondaryHair").Handle.Material
local Gender = rep.MaleFemale.Value
local Trait = rep.TraitChoosing.Value
local Spawn = "Outcast Lands"
--End
    local function UpdateStats(Value)
        Value[1] = BodyColors
        Value[2] = PrimaryHair
        Value[3] = PriColorHair
        Value[4] = PriNeon
        Value[5] = SecondaryHair
        Value[6] = SecColorHair
        Value[7] = SecNeon
        Value[8] = Gender
        Value[9] = Trait
        Value[10] = Spawn
        print(BodyColors, game.Workspace.Character.Head.BrickColor)
        for i = 1, #Value do
            print(Value[i])
        end
        return Value

    end
    CharInfoDDS:UpdateAsync(player.UserId, UpdateStats)
end)
0
You can't save instances to datastores. thats all I know why this error occurs. abnotaddable 920 — 6y
0
You can't save instances to datastores. thats all I know why this error occurs. abnotaddable 920 — 6y

2 answers

Log in to vote
0
Answered by
luadotorg 194
6 years ago

Roblox has removed saving arrays in DataStore since a long time ago.

I know it sucks, but we can't really do anything about it.

Try saving your data as different asyncs.

0
hm, that's strange. I used `:SetAsync()` on one datastore that had an array and it worked SmugNyan 24 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

Yeah this can be annoying, but you should be able to get around it by doing something like

local DDS = game:GetService("DataStoreService")
local CharInfoDDS = DDS:GetDataStore("CharactInfo")



--loading
local data = CharInfoDDS:GetAsync("somevalue")
data = game:GetService("HttpService"):JSONDecode(data)

-- saving
local data = {}
game:GetService("HttpService"):JSONEncode(data)
CharInfoDDS:SetAsync("somevalue", data)

This should work out just fine. Please correct me if I'm wrong.

0
Well, the reason some people like saving actual tables, is because they are easier to read because we are more familiar. Not saying JSON tables are hard to read, though. hiimgoodpack 2009 — 6y
0
Also, you never do anything with the JSON table you encoded. hiimgoodpack 2009 — 6y
0
o.o SmugNyan 24 — 6y

Answer this question