it is not saving my data and gives me error saying 104: Cannot store Array in data store. Data stores can only accept valid UTF-8. this error happened when i wanted to save Inventory as well line 58
in Script
local sp = script.Parent;
local Main = sp.Parent;
local Modules = Main:WaitForChild("Modules");
local DataStoreSettings = require(Modules:WaitForChild("Settings"));
local BackpackData = game:GetService("DataStoreService"):GetDataStore(DataStoreSettings.DataStore.BackpackData);
local StatsData = game:GetService("DataStoreService"):GetDataStore(DataStoreSettings.DataStore.StatsDataStore);
local DataStoreModule = require(Modules:WaitForChild("DataStore"));
local GameType = game:GetService("RunService"):IsStudio();
local Stats = {
{"Total Clicks","NumberValue",0,true};
{"Money","NumberValue",0,true};
}
--[[
{
"Playing", -- Value Name
"BoolValue", -- Value Type
false, -- Value
false -- will it be in leaderstats folder or in player false = player true = leaderstats
};
--]]
function PlayerAdded(Player)
local leaderstats = Instance.new("Folder");
leaderstats.Name = "leaderstats";
leaderstats.Parent = Player;
for i,v in next,Stats do
if (v[4]) then
local Value = Instance.new(v[2]);
Value.Name = v[1];
Value.Value = v[3];
Value.Parent = leaderstats;
else
local Value = Instance.new(v[2]);
Value.Name = v[1];
Value.Value = v[3];
Value.Parent = Player;
end
end
local BackpackStats = Instance.new("Folder");
BackpackStats.Name = "BackpackData";
BackpackStats.Parent = Player;
Instance.new("NumberValue",BackpackStats).Name = "Holds";
Instance.new("Color3Value",BackpackStats).Name = "Color";
Instance.new("NumberValue",BackpackStats).Name = "Clicks";
DataStoreModule.LoadData(Player,BackpackStats,BackpackData);
DataStoreModule.LoadData(Player,leaderstats,StatsData);
end
function PlayerLeft(Player)
local err,done = pcall(function()
BackpackData:SetAsync(Player.UserId,DataStoreModule.SaveData(Player.BackpackData));
StatsData:SetAsync(Player.UserId,DataStoreModule.SaveData(Player.leaderstats));
end)
print(done) -- here
if (GameType == false) then
game:GetService("TeleportService"):Teleport(game.PlaceId,Player);
end
end
game.Players.PlayerRemoving:Connect(PlayerLeft);
game.Players.PlayerAdded:Connect(PlayerAdded)
if (GameType == true) then
game.OnClose = function()
for i,v in next,game.Players:GetChildren() do
PlayerLeft(v);
end
while wait() do
end
end
end
DataModule
local function LoadData(Player,Inventory,Data)
local UserData;
pcall(function()
UserData = Data:GetAsync(Player.UserId);
end)
if (UserData) then
for i,v in next,UserData do
--[[
v = {name = v.Name;value = v.Value}
--]]
if (Inventory:FindFirstChild(v.name)) then
Inventory[v.name].Value = v.value;
else
warn(v.name.." is not a valid member of "..Inventory.Name)
end
end
end
end
local function SaveData(Inventory)
local DataSave = {};
for i,v in next,Inventory:GetChildren() do
local TempData =
{
name = v.Name;
value = v.Value;
};
-- TempData = {name = v.Name;value = v.Value}
table.insert(DataSave,TempData);
end
return DataSave;
end
local Module = {};
Module.LoadData = LoadData;
Module.SaveData = SaveData;
return Module;
Settings Module
local DatStore = {
StatsDataStore = "ecawdawdawd",
BackpackData = "vdfdsfdsfds"
}
local Module = {}
Module.DataStore = DatStore;
return Module
