So I was just starting to learn today about how to save multiple pieces of data to one key using DataStoreService. However, when I’m trying to save, either as an array or a table, it says (Array or dictionary, depending on which table type I'm trying to save) is not allowed in data stores.
I watched this video, as well as looking at other DevForum posts, and they seem to do the same thing I’m doing, but it actually works for them. I have enabled API access for DataStores. Any suggestions?
local DataStoreService = game:GetService("DataStoreService")
local playerDataStore = DataStoreService:GetOrderedDataStore("PlayerData")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder",player)
leaderstats.Name = "leaderstats"
local coins = Instance.new("IntValue",leaderstats)
coins.Name = "Coins"
local gems = Instance.new("IntValue",leaderstats)
gems.Name = "Gems"
local success, errorMessage = pcall(function()
playerDataTable = playerDataStore:GetAsync(player.UserId)
print(playerDataTable)
end)
if success and playerDataTable == nil then
print("First-Time Player!")
player.leaderstats.Coins.Value = 100
player.leaderstats.Gems.Value = 10
else
player.leaderstats.Coins.Value = playerDataTable[1]
player.leaderstats.Gems.Value = playerDataTable[2]
end
game.Workspace:WaitForChild("ShinyPart").ClickDetector.MouseClick:Connect(function()
player.leaderstats.Coins.Value += 100
player.leaderstats.Gems.Value += 10
end)
end)
game.Players.PlayerRemoving:Connect(function(player)
local playerDataTable = {}
playerDataTable[1] = player.leaderstats.Coins.Value
playerDataTable[2] = player.leaderstats.Gems.Value
playerDataStore:SetAsync(player.UserId,playerDataTable)
end)