So, I've been trying to work around a hat removal script when a player first enters a server, but they have not been working. Does anyone know how to do so? My entire script is:

local player = game:GetService("Players").LocalPlayer
game.Players.PlayerAdded:connect(function()
	for _, object in pairs(player.Characer:GetChildren()) do
		if object:IsA("Hat") then
			object:Destroy()
		end
	end
end)