Saving script isn't working, please help!

I’ve been working on a case opening system. When the case is opened it puts and item in your inventory GUI. I’ve been trying to save that. but it isn’t working. I’ve tried storing a table and using SetAsync to save it.
This is the local script code:

local owns = {}
local times = 0
local number = 0 -- Might need to change
local items = require(game.ReplicatedStorage.Items)
local price = 1000
local time = 2.5
local debounce = true
local player = game.Players.LocalPlayer
local case = require(game.StarterGui.Modules.case)
local Item1 = player.PlayerGui.Inventory.Frame.Item1


script.Parent.MouseButton1Click:connect(function()
	if player.leaderstats.Eggs.Value >= price then
		if debounce == true then
			player.leaderstats.Eggs.Value = player.leaderstats.Eggs.Value - price
			debounce = false
			local a = require(game.Players.LocalPlayer("WaitForChild","PlayerGui")("WaitForChild","Modules")("WaitForChild","case")):create("Classic")
			if Item1.Visible == false then
				Item1.Text = tostring(a)
				player.PlayerGui.Inventory.Frame.Item1.Visible = true
				table.insert(owns, Item1)
			else
				number = number + 2
				local Item = Item1:clone()-- Might need to change
				Item.Text = tostring(a)
				Item.Position = UDim2.new(.097 * number,0,.08 * times,0)-- Might need to change
				Item.Parent = Item1.Parent
				table.insert(owns, Item)
				if number == 10 then
					number = 0
					times = times + 1
					Item.Position = UDim2.new(.097 * number,0,.08 * times,0)
				end
			end
			game.ReplicatedStorage.save:FireServer(player.UserId, owns)
			print(a)			
			wait(time)
			debounce = true
		end
	end
end)

This is where the Remote function fires:


local DataStore = game:GetService("DataStoreService"):GetDataStore("ownsData")
local Players = game:GetService("Players")
 
Players.PlayerAdded:Connect(function(player)
	local PlayerData = DataStore:GetAsync(tostring(player.UserId))
	if PlayerData ~= nil then
		print(PlayerData)
		PlayerData.Parent = player.PlayerGui.Inventory.Frame
	end
end)

game.ReplicatedStorage.save.OnServerEvent:Connect(function(UserId, owns)
	DataStore:SetAsync(tostring(UserId), owns)
end)

Roblox’s DataStore has no support for saving instances, in this case, your guis. This is because JSON does not support Roblox’s instances. You’ll have to find another way to do your saving.

He/she could, but this may pass Roblox’s Datastore limits if the object he/she is trying to save is big enough. View Datastore’s Limits & Errors

DataStores can’t store actual instances. Read here what they can store

Have unique strings for each item, add that string into the table, save the table. Then unload the table, and add the items by the unique string into the GUI.

If that didn’t make sense, here’s this it doesn’t account for FilteringEnabled so if you can’t figure out how to transfer it, let me know.

----- Services -----

local dataStoreService = game:GetService('DataStoreService')

local players = game:GetService('Players')

----- DataStores -----

local dataStore = dataStoreService:GetDataStore("bleh")

local playerItems = {}

----- Other -----

local gui = (wherever the gui is)

----- Functions -----

local function addItem()

table.insert(playerItems, "CustomItemString")

end

local function saveTable()

dataStore:SetAsync("key", playerItems)

end

local function loadTable()

local savedItems = dataStore:GetAsync("key")

if savedItems then

for _, item in pairs(savedItems) do

table.insert(playerItems, item)

local itemSlot = Instance.new("ImageButton") -- whatever you use to display it

itemSlot.Image = "" --- whatever image that is associated with the string, you

-- can have a dictionary for this such as

--[[

local stringtoImage = {

['CustomItemString'] = "rbxassetid://"

}

itemSlot.Image = stringtoImage[item]

--]]

itemSlot.Parent = gui

end

end

end

----- Code -----

players.PlayerAdded:connect(function(player)

loadTable()

end)