Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why does this not get the players hat's?

Every Time it prints it just prints parts of the player not all the children such as hats or mesh's

player.CharacterAdded:connect(function()
		wait(.2)
	local character = player.Character:GetChildren()
	for i,v in pairs(character) do
	
		if v.className == "Hat" then
			print(v.Name)
		end
		if v.className == "Decal" then
			print(v.Name)
		end
		if v:IsA("CharacterMesh") then
			print(v.Name)
		end	
	end
	
end)

1 answer

That's because you have it printing the object no matter what it is. (print(v))

Also, you can't get ALL children just with one iteration.

function search(parent)
	for i, v in pairs(parent:children()) do
		-- Your code here.

		if #v:children() > 0 then
			search(v)
		end
	end
end

game.Players.PlayerAdded:connect(function(player)
	player.CharacterAdded:connect(function(character)
		search(character)
	end)

	wait(1)

	player:LoadCharacter() -- Makes sure it calls the CharacterAdded event on first spawn.
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.