I'm tried to make inventory save and when player leaving creating new table with items. But this is not saving

I'm not getting an error

Code: (Server Script)

local DSS = game:GetService("DataStoreService"):GetDataStore("NewDStestq312")
local RS = game:GetService("ReplicatedStorage")

game.Players.PlayerAdded:Connect(function(Player)
	local Key
	Key = Player.UserId
	local Folder = Instance.new("Folder",RS)
	Folder.Name = Player.Name.."-Inventory.UID-"..Player.UserId
	local getData = DSS:GetAsync(Player.UserId)
	if getData then
		print("Test")
	end
end)

game.Players.PlayerRemoving:Connect(function(Player)
	local Key
	local newTable = {}
	Key = Player.UserId
	local findData = RS:FindFirstChild(Player.Name.."-Inventory.UID-"..Player.UserId)
	if findData then
	   for i,v in pairs(findData:GetChildren()) do
		   local findNames = v.Name
		   table.insert(newTable,findNames)
	   end
	   wait()
	   DSS:SetAsync(Key,newTable)
	end
end)

2 comments

0

The key needs to be a string. Set key to something like Key = "Player_"..Player.UserId and the parent argument to Instance.new is deprecated and is known to slow down game performance. Unless your game is a lag simulator, do not use it.

0

I'm not doing a simulator.....................................................