I have this script, it is supposed to get the children of a model in the player, and then take the names of the children and turn them into a variable, and then print the variable. It sort of works, but it will only get the names of 3 children. Can anyone help?

game.Players.PlayerRemoving:connect(function(plr)
	local items = plr.items:Clone()
	items.Parent = game.ServerStorage
	items.Name = plr.Name.." items"
	local saveItems = plr.Name..": "
	local getItems = items:GetChildren()
	for i, v in pairs(items:getChildren())do
		saveItems = saveItems..(v.Name).." + "
		print(saveItems)
	end
	print(saveItems.."!!!")
end)

3 comments

0

Which three children? Why do you expect it to get more? Can you show the hierarchy? (e.g., screenshot or type it out)

0

This should work, unless you're attempting to print names of children of children inside the model, in that case you'll need to use recursion. Also I suggest making a table full of all the names then using table.concat, or unpack to print them all.

0

Maybe the model is being removed as the player leaves the game, so some of the parts are missing when the script gets to them.