What the title says. I’m using this system by ForeverHD and made a quick datastore script for the Inventory folder:
wait(1)
local DataStoreService = game:GetService("DataStoreService")
local SaveData = DataStoreService:GetDataStore("CharacterSaving_1")
local fakeLeaderstats = game:GetService("ServerStorage"):FindFirstChild("FakeLeaderstats").Inventory
game.Players.PlayerAdded:Connect(function(player)
local CharacterFolder = player:WaitForChild("leaderstats").Inventory
local CharData = SaveData:GetAsync(player.UserId)
if CharData ~= nil then
for i, v in pairs(CharData) do
if fakeLeaderstats:FindFirstChild(v) and CharacterFolder:FindFirstChild(v) == nil then
fakeLeaderstats[v]:Clone().Parent = CharacterFolder
end
end
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local CharTable = {}
for i,v in pairs(player.leaderstats.Inventory:GetChildren()) do
table.insert(CharTable, v.Name)
end
if CharTable ~= nil then
SaveData:SetAsync(player.UserId, CharTable)
end
end)
It doesn’t seem to save stuff though, and no error in output.
Then again I suck at anything DataStore related, so I probably have something wrong in my script.
For the Part where you are inserting values you are only inputting the names which could be wrong and when you are checking to see if it ~= nil it will always fire since an empty table still doesnt == nil
Edit - Just noticed the wait(1) at the top – maybe people are joining before the PlayerAdded connection is made?
local function PlayerAdded(plr)
stuff
end
game.Players.PlayedAdded:Connect(PlayerAdded)
for i, v in pairs(game.Players:GetPlayers()) do
PlayerAdded(v)
end
cause this makes sure if they joined before the event was connected they would still be considered added