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

Array is not Allowed in Data Stores Error?[Solved]

Asked by 5 years ago
Edited 5 years ago

I have been trying to script a data store but this is my first time using ordered data stores usually I use normal ones. And I am getting an error that says "Array is not allowed in data stores"

Ive never had this error before but again Ive never used ordered data stores before so.

Heres my code. The error is on line 55.

local Players = game:GetService("Players")

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local DataStoreService = game:GetService("DataStoreService")



function LoadData(Player)

    local DataFolder = Instance.new("Folder")

    DataFolder.Name = Player.UserId

    DataFolder.Parent = ReplicatedStorage:WaitForChild("DataFolder")

    local DataStore = DataStoreService:GetOrderedDataStore(Player.UserId)

    local DataPages = DataStore:GetSortedAsync(false, 100)

    local Data = DataPages:GetCurrentPage()

    for Index, Object in pairs(Data) do

        print(Object.Key, Object.Value)

    end

-- if Data.IsFinished == false then

-- Data:AdvanceToNextPageAsync()

-- end

end



function SaveData(Player)

    local DataToSave = {}

for Index, Object in pairs(ReplicatedStorage.DataFolder[Player.UserId]:GetDescendants()) do

    if Object:IsA("IntValue") or Object:IsA("NumberValue") or Object:IsA("StringValue") or Object:IsA("BoolValue") then

        table.insert(DataToSave, Object.Value)

    end

end

local DataStore = DataStoreService:GetOrderedDataStore(Player.UserId)

DataStore:SetAsync(Player.UserId, DataToSave)

end



Players.PlayerAdded:Connect(LoadData)

Players.PlayerRemoving:Connect(SaveData) 

Thank you for your time and hopefully we can figure this out because data saving is important XD

1 answer

Log in to vote
0
Answered by
DollorLua 235 Moderation Voter
5 years ago

Line 53 you might want to change to something more like...

local DataStore = DataStoreService:GetDataStore() and also I recommend using Dictionaries instead of a table EX:

local DataToSave = {} DataToSave[Cash] = plr.leaderstats.Cash.Value

I personally use that but the array might work if you change it to DataStoreService:GetDataStore("DATASTORE_NAME")

0
I would accept this answer its just I am trying to use ordered data stores instead of the normal ones because of something I am doing. GottaHaveAFunTime 218 — 5y
0
are you making a Global Leaderboard? DollorLua 235 — 5y
Ad

Answer this question