Hat clone when clicked

Hello, I am cozfl and I need help with my script here, I want to make a hat clone onto the player’s head and delete the other hats on the head when done so, There are no errors shown anywhere, But the hat doesn’t clone. The accessories are removed though. Here is the code I have:

local ServerStorage = game:GetService("ServerStorage")
local RealHats = ServerStorage.RealHats:GetChildren()

local FakeHats = workspace:WaitForChild("FakeHats"):GetChildren()

local function GiveHat(player,FakeHat)

local Character = player.Character or player.CharacterAdded:Wait()
local HatCheck = Character:FindFirstChild(FakeHat.Name)
local Humanoid = Character:WaitForChild("Humanoid")

Humanoid:RemoveAccessories()

if not HatCheck then
	for i,RealHat in pairs(RealHats) do
		if FakeHat == RealHat.Name then
			local ClonedHat = RealHat:Clone()
			Humanoid:AddAccessory(ClonedHat)
		end
	end
	
end

end

for i,FakeHat in pairs(FakeHats) do

local Handle = FakeHat:FindFirstChild("Handle")
local ClickDetector = Handle.ClickDetector

if Handle and ClickDetector then
	ClickDetector.MouseClick:Connect(function(player)
		GiveHat(player,FakeHat)
	end)
end
end

I did have a post here before from 2 days ago (I think its 2 days) but I’ve since changed the code so I made a new one.

Here are the objects included:
image
image

Each of the fakehats have a clickdetector inside.

If any further questions are required, do not hesitate to ask!
I apologize if I may not get exactly what you are saying, I am not good at understanding people.

Fake hats are the model hats, just to clarify. They are what you click.

Try setting the parent of the cloned hat before you use “:AddAccessory()”
Also add “print()” statements after every if statement to see which one isn’t parsing