DataStore script doesn't save the values inside a folder

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.

I’ve tried to modify existing DataStore scripts that save tools on leave to save the values inside of the folder too, but nothing worked

Have you placed print statements at key points to see if anything is being saved and if anything is being loaded?

No, I’m going to try this though, I completely forgot about trying that. Thanks for reminding me!

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?

I tried without the wait aswell, didn’t work

usually when i do a PlayedAdded thing i would do

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

Ok guys idk what i did but it suddenly began working

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.