Datastore not saving properly?

I am making a cosmetic system and it won’t save it to the datastore.
Although my banning system works perfectly.

Banning system:

					if target.UserId ~= 129324589 then
						local reason = 'Banned.'
						if args[2] ~= nil then
							for thenum,i in pairs(args) do
								if thenum ~= 1 then
									reason = reason .. ' ' .. i
								end
							end
						end
						local id = target.UserId
						target:Kick(reason)
						datastore:SetAsync(tostring(id) .. 'Banned', {currentlyBanned = true, Reason = reason})

Cosmetic Datastore:

local dt = game:GetService("DataStoreService")

local storage = dt:GetDataStore('PlrCosmetics')

game:GetService("Players").PlayerAdded:Connect(function(plr)
	local list = script:WaitForChild("CosmeticList"):Clone()
	list.Parent = plr
	list.Name = 'PlayerCosmetics'
	
	local datastore = storage:GetAsync(plr.UserId .. 'Cosmetics')
	
	for _,value in pairs(datastore) do
		if list:FindFirstChild(value[1]) ~= nil then
			list:FindFirstChild(value[1]).Value = value[2]
		end
	end
end)

game:GetService("Players").PlayerRemoving:Connect(function(plr)
	local list = plr:WaitForChild("PlayerCosmetics")
	
	local itemList = {}
	
	for _,i in pairs(list:GetChildren()) do
		if i:IsA("BoolValue") or i:IsA("StringValue") then
			local newTable = {}
			table.insert(itemList, newTable)
			table.insert(newTable, 1, i.Name)
			table.insert(newTable, 2, i.Value)
		end
	end
	
	storage:SetAsync(plr.UserId .. 'Cosmetics', itemList)
end)
1 Like

When the items are saved PlayerRemoved add a

print(itemList)

And see if the list of items are being saved.

If you’re not getting any errors, just use a bunch of print’s to see where the code does not work.

1 Like

Alright so the item it saves has all the data it needs. But when it retrieves it from the datastore is just gives a string that says ‘None’

I found what it was. I accidentally was retrieving two different things. Its fixed now.

1 Like

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