Well, I’ve seen some topics about this error on the DevForum but I don’t understand what I have to do
Script
local Players = game:GetService("Players")
local RS = game:GetService("ReplicatedStorage")
local AFK = RS.Events.AFK
local Warn = RS.Events.AssetsLoadedOutput
local Titles
local DataStoreService = game:GetService("DataStoreService")
local TitlesData = DataStoreService:GetDataStore("TitlesData")
local function ChangeAFKProperty(Player, Value)
Player:SetAttribute("AFK", Value)
-- print("AFK = ", Value)
end
local function AssetsLoaded(Player)
Player:SetAttribute("AssetsLoaded", true)
end
Players.PlayerAdded:Connect(function(Player)
local stats = Instance.new("Folder")
stats.Parent = Player
stats.Name = "leaderstats"
local Owls = Instance.new("IntValue")
Owls.Value = 8000
Owls.Name = "Owls"
Owls.Parent = stats
Titles = Instance.new("Folder")
Titles.Name = "Titles"
Titles.Parent = Player
local Data = {"nothing"}
local success, errormessage = pcall(function()
Data = TitlesData:GetAsync(Player.UserId)
end)
if success then
for _,Object in pairs(Data) do
Object.Parent = Titles
end
else
print("Error while getting your data")
warn(errormessage)
end
Player:SetAttribute("AFK", false)
Player:SetAttribute("InGame", false)
Player:SetAttribute("AssetsLoaded", false)
Player.CharacterAdded:Connect(function()
Player:SetAttribute("InGame", false)
Player:SetAttribute("AssetsLoaded", false)
end)
end)
game.Players.PlayerRemoving:Connect(function(Player)
local TitleData = {}
for _,Object in pairs(Titles:GetChildren()) do
table.insert(TitleData, Object)
end
TitlesData:SetAsync(Player.UserId, TitleData)
end)
AFK.OnServerEvent:Connect(ChangeAFKProperty)
Warn.OnServerEvent:Connect(AssetsLoaded)
There are some extra things about the Game, but the main thing is that Datastore doesn’t save the Titles.
Context: When buying an item, the server adds the Item to the Player in a folder, the Client detects this and adds it to his Inventory with ChildAdded, and when the Player exits I want everything inside that Folder to save, but it gives this error.
What can I do?