How do i use pcall to save an instance

the items in the plr.Backpack do not appear (and are not printed) when i rejoin

game.Players.PlayerAdded:Connect(function(plr)
	local folder = Instance.new("Folder", plr)
	folder.Name = 'leaderstats'
	
	local rolls = Instance.new("IntValue", folder)
	rolls.Name = 'Rolls'
	rolls.Value = 0
	
luckmultiplier = Instance.new("IntValue", plr)
	luckmultiplier.Name = 'Luck'
	luckmultiplier.Value = 1
	
	local playerid = "Player_" .. plr.UserId
	local data = rollstore:GetAsync(playerid)

	if data then
		rolls.Value = data['Rolls']
	else
		rolls.Value = 0
	end
	
	print(data["Items"])
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local datatobesaved = {
		Rolls = plr.leaderstats.Rolls.Value,
		Items = plr.Backpack:GetChildren()
	}
	local playerid = "Player_" .. plr.UserId

	local success, err = pcall(function()
		rollstore:SetAsync(playerid,datatobesaved)
	end)
	
	if success then
		print("data saved!")
	else
		print("data failed to save!")
	end
end)

You’re trying to save an instance to the store. Try saving their names, or values, and doing stuff with those instead to get them to the backpack.

GetAsync() also needs a pcall().

but i need to save an object, not a name

game.Players.PlayerAdded:Connect(function(plr)
	local folder = Instance.new("Folder", plr)
	folder.Name = 'leaderstats'
	local rolls = Instance.new("IntValue", folder)
	rolls.Name = 'Rolls'
	rolls.Value = 0
	
luckmultiplier = Instance.new("IntValue", plr)
	luckmultiplier.Name = 'Luck'
	luckmultiplier.Value = 1
	
	local playerid = "Player_" .. plr.UserId
	local data = rollstore:GetAsync(playerid)
print(data['Rolls'])
	if data then
		rolls.Value = data['Rolls']
	else
		rolls.Value = 0
	end
	
	for i,v in pairs(data['Items']:GetChildren()) do
		v.Parent = plr.Backpack
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local datatobesaved = {
		Rolls = plr.leaderstats.Rolls.Value,
		Items = plr.Backpack
	}
	local playerid = "Player_" .. plr.UserId

	local success, err = pcall(function()
		rollstore:SetAsync(playerid,datatobesaved)
	end)
	
	if success then
		print("data saved!")
	else
		print("data failed to save!")
	end
end)

Why do you need to save the object? You could just save each element in a dictionary.

I guess you could try HttpService:JSONEncode() to save encoded data and HttpService:JSONDecode() to load and decode data. Not sure if it would work, though.

sryy but im not that advanced in coding so fym

Try using JSONEncode and JSONDecode.

Two lines need changing, and one line needs adding.

At the top of the script:
local httpService = game:GetService("HttpService")

Then, when saving and loading:

local data = httpService:JSONDecode(rollstore:GetAsync(playerid))

Then, when saving:

rollstore:SetAsync(playerid, httpService:JSONEncode(datatobesaved))

You might need some more code to make this work, though.