while true do
	wait()
	local player = game.Players.LocalPlayer
	local plr = game.Players.LocalPlayer.Character
	if player then
		if plr then
			if player.HatEquiped.Value ~= "Empty" then
				for i,v in pairs(plr:GetChildren()) do
					if v.ClassName == "Hat" then
						local verification = v:FindFirstChild("HatVerifier")
						if verification then
							local hatwearing = v.Name
							if player.HatEquiped.Value ~= hatwearing then
								v:Destroy()
								local hatnowwearing = game.ReplicatedStorage:FindFirstChild(""..player.HatEquiped.Value..""):Clone()
								if hatnowwearing then
									hatnowwearing.Parent = plr
								end
							end
						elseif verification == nil then
							local hatnowwearing = game.ReplicatedStorage:FindFirstChild(player.HatEquiped.Value)
							if hatnowwearing then
								local hatputtingon = game.ReplicatedStorage:FindFirstChild(""..player.HatEquiped.Value..""):Clone()
									hatputtingon.Parent = plr
							end
						elseif v.ClassName ~= "Hat" then
							local hatnowwearing = game.ReplicatedStorage:FindFirstChild(player.HatEquiped.Value)
							if hatnowwearing then
								local hatputtingon = game.ReplicatedStorage:FindFirstChild(""..player.HatEquiped.Value..""):Clone()
									hatputtingon.Parent = plr
							end
						end
					end
				end
			end
		end
	end
end

This script is supposed to have the player wear that hat that their HatEquiped value is set to. I'm going to try to sum it up.

This is for a character customization script. Each hat in my game in Replicated Storage has a value in it (the value's value makes no change) to show the script that it's the game's hat, and not ROBLOX's hat. If there is a hat in the player that is the game's hat, it's supposed to get rid of it when HatEquiped changes. If there is no hat that the player is wearing, then it gives the hat to the player if the player's HatEquiped value is the name of a hat in Replicated Storage, then it clones it over to the player. The problem is that it doesn't work, and I don't know why. There is no error in the output, and no error that I can find. Please help?