Get Player Character After Leaving

what about you check if any children gets added to the player’s character which would be the accessory & make sure that it has that attribute so it wouldn’t save any accessory.

char.ChildAdded:Connect(function(child)
if child:IsA("Accessory") and child:GetAttribute("Item") then
-- Stores the Accessory
end
end)
1 Like

08:37:40.503 Character is not a valid member of Players “Players” - Server - CharacterData:79

1 Like

well the thing is that im also adding groups, so i want to make sure that whatever type of item i do instead of being specific I can just guide the script by Name

1 Like

sorry if my replies are slow or no replies at all im reading and understanding while i work on this

1 Like

characterremoving doesnt work sadly

1 Like

game.Players doesnt have property Character i guess you meant to type Player.Character instead of Players.Character in your code

1 Like

i will take a look into them and see if i can get something working with your method, it sounds quite smart and simple so ill probably try it

2 Likes

cuz if you don’t specify your items it will save every accessory in your character.

1 Like

oh i know, thats why i said i wanted to use names instead so basically even if its an accessory or a group as long as it has the specific name i want it will be selected, which is what i did for my other scripts

1 Like

You mean it not even fire at all?

1 Like

it would print nil you can try it yourself.

1 Like

oh oops, still getting an error tho

08:44:55.527 ServerScriptService.CharacterData:92: attempt to index nil with ‘GetDescendants’ - Server

	game.Players.PlayerRemoving:Connect(function(plr)
	local char = plr.Character
	local playerUserId = plr.UserId
	local accessorySave = {}
	
		local inv = plr:FindFirstChild('Inventory')

		for _,acc in pairs(inv:GetChildren()) do
			table.insert(accessorySave, acc.Name)
		end

		local inv = plr:FindFirstChild('Inventory')
		local characterSave = {}

		for _,charS in pairs(char:GetDescendants()) do
			for _,items in pairs(inv:GetChildren()) do
				if charS.Name == items.Name then
					table.insert(characterSave, charS.Name)
					print(characterSave)

				end
			end
		end

		local success, errorMessage = pcall(function()
			contributorDS:SetAsync("UserInventory-"..player.UserId, characterSave, accessorySave) --Save
		end)
end)

its this part that gives me error

		for _,charS in pairs(char:GetDescendants()) do
1 Like

that error has nothing to do with those 2 lines.

1 Like

edited it and fixed it , my bad

1 Like