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
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")