Getting a characters shirt consistently every time

I want to get a characters shirt every time (if they have a shirt), but my problem is FindFirstChild() doesnt wait for it to be added and if the player doesnt have a shirt then WaitForChild() breaks the script, how could i fix this problem?

--HELP!!
local Shirt = char:FindFirstChildWhichIsA("Shirt")

I have had issues like this over and over.

The best solution I have found is to wait for the character to be part of Workspace.

Example:


local Players = game:GetService("Players")
local Workspace = game:GetService("Workspace")

local function WorkspaceChildAdded(Child)
	if Child:IsA("Model") then
		local Player = Players:GetPlayerFromCharacter(Child)
		if Player then
			print("Player =", Player.Name)
			local Character = Player.Character
			local Shirt = Character:FindFirstChildWhichIsA("Shirt")
			if Shirt then
				print("Shirt Found", Shirt)
			end
		else
			print("Not a player.")
		end
	end
end
Workspace.ChildAdded:Connect(WorkspaceChildAdded)

Run that code when the CharacterAppearanceLoaded has ran

Eg:

game.Players.OnPlayerAdded:Connect(function(player)
   local connection = player.CharacterAppearanceLoaded:Connect(function(character)
           local Shirt = character:FindFirstChildWhichIsA("Shirt")
   end)
   player.AncestryChanged:Wait()
   connection:Disconnect()
end)
1 Like

how would i do this on a local script?

here is my attempt:

local function PlrAdded(player)
	
	local newShirt
	local connection = player.CharacterAppearanceLoaded:Connect(function(character)
		local plrShirt = character:FindFirstChildWhichIsA("Shirt")
		if newShirt then
			newShirt = plrShirt
		end
	end)
	print("DOING")
	player.AncestryChanged:Wait()
	print("FINE")
	connection:Disconnect()
	return newShirt
	
end

local shirt = PlrAdded(game.Players.LocalPlayer)
local function getShirt(plr : Player)
	if not plr:HasAppearanceLoaded() then
		plr.CharacterAppearanceLoaded:Wait()
	end

	return plr.Character:FindFirstChildOfClass("Shirt")
end
local shirt = getShirt(game.Players.LocalPlayer)
2 Likes

worked perfect for me, thanks!

1 Like