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:

local DataStoreService = game:GetService("DataStoreService")
local SaveData = DataStoreService:GetDataStore("CharacterSaving_1")
local fakeLeaderstats = game:GetService("ServerStorage"):FindFirstChild("FakeLeaderstats").Inventory

	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


	local CharTable = {}

	for i,v in pairs(player.leaderstats.Inventory:GetChildren()) do
		table.insert(CharTable, v.Name)
	if CharTable ~= nil then
		SaveData:SetAsync(player.UserId, CharTable)

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)

for i, v in pairs(game.Players:GetPlayers()) do

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.