How to make this a "Item Compatible" script?

I mean, this is the same topic as my last post, just that it has a different achievement, I would like to know how would this script become “Item Compatible”

Code:

local Handle = script.Parent
local CD = script.Parent.ClickDetector

function on ()
	isOn = true
	Handle.Transparency = 0
end

function off()
	isOn = false
	Handle.Transparency = 1
end

function onClicked()
	if isOn == true then off() else on() end
end

CD.MouseClick:Connect(onClicked)
on()

local isOn = true
local Handle = script.Parent
local CD = script.Parent.ClickDetector

function on ()
	isOn = true
	Handle.Transparency = 0
end

function off()
	isOn = false
	Handle.Transparency = 1
end

function onClicked()
	if isOn == true then off() else on() end
end

CD.MouseClick:Connect(onClicked)
on()

What I need to achieve here is just so that the player’s hat could become transparent, and when clicked again, the hat is back on.

Im guessing this is what you mean? Could you explain a little more what you mean by “Item Compatible”? Like the script works running on a item?

local Handle = script.Parent
local CD = Handle.ClickDetector
local isOn = true

function on()
	isOn = true
	Handle.Transparency = 0
end

function off()
	isOn = false
	Handle.Transparency = 1
end

function onClicked()
	if isOn == true then
	   off()
	  else 
	   on()
	  end
end

on()
CD.MouseClick:Connect(onClicked)

Technically, yes, working on an avatar item, like that morph type of thing.

Ok, So if your trying to make a users avatar item invisible, you would have to subdirectory down into it. So navigate into the Players character to where their accessories are located.

Then use like a for i,v in pairs() loop, then you can check if the v item is a hat accessory. If it is then run the code to make it invisible. Then use your toggle method to make it able to be switched. Hope that helps.