DataStore is saying that an accessory has been saved, but nothing was saved

So, I’ve recently completed my accessory datastore. And when I tested it, the output said that everything was saved. But when I rejoin, the accessory has not been saved and it’s gone. Any help?

Here’s the code for the data store:

local DataStoreService = game:GetService("DataStoreService")

local DataStoreName = DataStoreService:GetDataStore("myDataStore")



local player = game.Players.LocalPlayer
game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(Character)
		
		local DominoValue = Instance.new("BoolValue")
		DominoValue.Name = "Domino"
		DominoValue.Parent = player
		local DominoItem = game.ReplicatedStorage.Hats.Domino

		if DominoValue.Value == true then
			local Folder = Instance.new("Folder")
			Folder.Name = "Hats"
			Folder.Parent = Character.Head
			local Head = Character.Head
			local New_Hat = DominoItem:Clone()
			New_Hat.Parent = Folder
			New_Hat.Position = Head.Position
			local Weld = Instance.new("Weld")
			Weld.Parent = New_Hat
			Weld.Part0,Weld.Part1 = Head, New_Hat
			Weld.C0 = CFrame.new(0,1.4,0)
			Weld.C1 = Head.HatAttachment.CFrame
		end
	end)	
	local data 
	local success, errormessage = pcall(function()
		data = DataStoreName:GetAsync(player.UserId.."-Hats")
	end)
	
	if success then
		print("Hats loaded")
	else
		print("Error")
		warn(errormessage)
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	local success, errormessage = pcall(function()
		DataStoreName:UpdateAsync(player.UserId.."-Hats",function(old)
			local newvalue = old
			newvalue = player.Domino.Value
			return newvalue
		end)
	end)
	
	if success then
		print("Hats have been saved.")
	else
		warn(errormessage)
	end
end)

You are trying to use update async to set the value. That wont work for text only numbers.

It still doesn’t save when I set it.

Turn the hats they have into a list.
Heres a rough base of how its done.

local Hats = {"Hat1","Hat2","Hat3"} -- Make the list from inv

----- Make into text
local HatsData = ""
for i = 1,#Hats do
    HatsData = HatsData + Hats[i] .. ","
end
-- Result would look like Hat1,Hat2,Hat3.
-- You can add numbers too if they have repeats of hats

---- Turning back into a list
local HatsData = Store:GetData() -- Your DataStore, you sort this out
local Hats = string.split(Data,",")

update async will not work here. you cannot do “Hat1” + “Hat2” as they are string not nubers.

SetAsync will have to be used to override the store with the new text. If your game is going to go big make backups and whatnot.

Note: DataStores are only intended to hold two data types, Numbers and string. You can only use one at the time so I advice using string regardless as you can do more with it. Avoid using UpdateAsync as it is known for being the worst function within the datastores and stick with GetAsync and SetAsync.