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 save a rig's data so later in the game i can give the body to the player's character so it'll work as character customization. I'm using datastore and I got this error when executing the script:

local DDS = game:GetService("DataStoreService")
local CharInfo = DDS:GetDataStore("CharInfo")

game.Players.PlayerAdded:Connect(function(player)
    local BodyColors = Instance.new("BrickColorValue",player) -- Get this info off workspace.Character
    BodyColors.Name = "BodyColors"
    local PrimaryHair = Instance.new("IntValue",player) -- Save the meshID
    PrimaryHair.Name = "PrimaryHair"
    local PriColorHair = Instance.new("BoolValue",player) -- PrimaryHair Color
    PriColorHair.Name = "PriColorHair"
    local PriNeon = Instance.new("BoolValue",player) -- PrimaryHair is neon
    PriNeon.Name = "PriNeon"
    local SecondaryHair = Instance.new("IntValue",player) -- Save the meshID
    SecondaryHair.Name = "SecondaryHair"
    local SecColorHair = Instance.new("BoolValue",player) -- SecondaryHair Color
    SecColorHair.Name = "SecColorHair"
    local SecNeon = Instance.new("BoolValue",player) -- SecondaryHair is neon
    SecNeon.Name = "SecNeon"
    local Gender = Instance.new("BoolValue",player) -- false is female, true is male
    Gender.Name = "Gender"
    local Trait = Instance.new("IntValue",player) -- Traits for char
    Trait.Name = "Trait"

    local id = player.UserId
    local Data = CharInfo:GetAsync(id)
    if Data then
        BodyColors.Value = Data[1]
        PrimaryHair.Value = Data[2]
        PriColorHair.Value = Data[6]
        PriNeon.Value = Data[7]
        SecondaryHair.Value = Data[3]
        SecColorHair.Value = Data[8]
        SecNeon.Value = Data[9]
        Gender.Value = Data[4]
        Trait.Value = Data[5] else
        local NewData = {BodyColors.Value,PrimaryHair.Value,SecondaryHair.Value,Gender.Value,Trait.Value,PriColorHair.Value,PriNeon.Value,SecColorHair.Value,SecNeon.Value}
        CharInfo:SetAsync(id,NewData)
    end 
end)

When I play it, it errors: "Cannot store Array in DataStore" which I'm assuming means that it can't store tables in datastore.

0
it can store tables. abnotaddable 920 — 6y
0
Why not just store a JSON table, it makes this error go away, and have it working. hiimgoodpack 2009 — 6y

Answer this question