Error with "FindFirstChildWhichIsA"

Hi I am having an error with “FindFirstChildWhichIsA”
Script

game.Players.PlayerAdded:Connect(function(player)
	print(player.Name)
	for i, v in pairs(game.Workspace:FindFirstChild(player.Name):FindFirstChildWhichIsA("Shirt")) do
		v:Destroy()
	end
end)

Error

ServerScriptService.Script:3: attempt to index nil with 'FindFirstChildWhichIsA'

Ok thank you I will try using that

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		for i,v in pairs(char:GetChildren()) do
			if v:IsA("Shirt") then
				v:Destroy()
			end
		end
	end)
end)
local players = game:GetService("Players")
local player = players.LocalPlayer or players.PlayerAdded:wait()
local character = player.Character or player.CharacterAdded:wait()
if character:FindFirstChild("Shirt") then
	character:FindFirstChild("Shirt"):Destroy()
end

Local script, place inside StarterPlayerScripts folder or StarterCharacterScripts folder.

1 Like