Values are not saving and is loading as nil

What do you want to achieve? I am trying to make a saving index with values

What is the issue? Whenever I try saving the value it does nothing and loading prints nil in the output.

What solutions have you tried so far? I tried changing the string value to a int value and adding prints to see where it’s not working.

While I was writing this I saw “Id-(My userid)” in the output but couldn’t make it do that again.

Output:

image

Script:

local datastore = game:GetService("DataStoreService"):GetDataStore("Littes")

game.Players.PlayerAdded:Connect(function(player)
	local key = "id"..player.userId
	
	local littes = Instance.new("Folder",player)
	littes.Name = "Littes"
	
	pcall(function()
		local littes = datastore:GetAsync(key)
		print(littes)
		if littes then
			for i,v in pairs(littes) do
				print(v)
				local litte = Instance.new("IntValue",littes)
				litte.Value = v
				litte.Name = v
			end
		end
	end)
end)

game.Players.PlayerRemoving:Connect(function(player)
	local key = "id-"..player.userId
	
	local folder = player:WaitForChild("Littes")
	
	pcall(function()
		local littes = {}
		for i, v in pairs(folder:GetChildren()) do
			if v then
				table.insert(littes,v.Value)
				print("saving" .. littes)
			end
		end
		datastore:SetAsync(key,littes)
		print(key)
	end)
end)

for i, v in pairs(workspace.Littes:GetChildren()) do
	if v:IsA("BasePart") then
		v.Touched:Connect(function(hit)
			if hit.Parent:FindFirstChild("Humanoid") then
				local player = game.Players:GetPlayerFromCharacter(hit.Parent)
				local folder = player:WaitForChild("Littes")
				if folder:FindFirstChild(v.Name) then
					--
				else
					local value = Instance.new("IntValue",folder)
					value.Value = v.Name
					value.Name = v.Name
					game.ReplicatedStorage.Remotes.LitteSound:FireClient(player)
				end
			end
		end)
	end
end

you’re saving id-1234 but retrieving id1234, furthermore I believe your loading script is failing.

	local littes = Instance.new("Folder",player) -- first declaration
	littes.Name = "Littes"
	
	pcall(function()
		local littes = datastore:GetAsync(key) -- second declaration
		print(littes)

Here you shadow your littes variable. the instances you create will attempt to be parented to the littes datastore key which should fail, but it is in a pcall.
It is not enough to just throw error-bound functions in a pcall you should check what values the pcall returns; the first is if it did not error the second will be the error message.

I fixed the id problem and changed the littes variable to folder and made it print the contents of the table but it prints “-”