I am trying to create a script that will save anything in a player's backpack when they leave and/or die, and load it back into their backpack when they return. Am I missing something here?
local DataStoreService = game:GetService("DataStoreService")
game.Players.PlayerAdded:connect(
function(Player)
local PlayerStore = DataStoreService:GetDataStore(tostring(Player.userId), "PlayerData")
local PlayerItems = PlayerStore:GetAsync("PlayerItems")
if not PlayerItems then
PlayerItems = Player.Backpack:GetChildren()
PlayerStore:SetAsync("PlayerItems", PlayerItems)
end
P.S. I am aware there isn't any code for when they die, because I don't know what I need to do for that.

5 comments
There should be a ) after the last end.
X| wow I missed that. thx! :)
no problem :P
But you need to find a different way to store the values. The items cannot be stored. The table needs to be strings, bools, or numbers
Please post an answer to your question if you solved it.