Local script not destroying click detector

So I made a script where the click detector will not be visible/get destroyed when clicked once

script.Parent.ClickDetector.MouseClick:Connect(function()
	local ClickDetector = script.Parent.ClickDetector
	ClickDetector:Destroy()
end)

I’ve tried using variables, still not working.
any other topic was not useful for me.

Local scripts parented under workspace don’t run unless parented inside the Player Character.

Is it only working in the player character?

A list of where a LocalScript can run under is in the documentation:

A LocalScript will only run Lua code if it is a descendant of one of the following objects:

What I was saying is there is that a local script only runs in Player specific Places like PlayerScripts, Character or ReplicatedFirst.

Just make sure you realize what you’re doing.

If you want to destroy a Part with a ClickDetector inside of it when its clicked, you’d want to do something like this in a Script:

-- Script
local part = workspace.Part
local clickDetector = part.ClickDetector

clickDetector.MouseClick:Connect(function()
    part:Destroy()
end)

You could just parent this Script to ServerScriptService, adjust the paths as necessary, and call it a day. The ClickDetector here will also be destroyed.

However if you actually want to destroy the ClickDetector itself when its clicked for a respective Part, you’d do:

-- Script
local part = workspace.Part
local clickDetector = part.ClickDetector

clickDetector.MouseClick:Connect(function()
     clickDetector:Destroy()
end)

Just make sure you aren’t parenting the Script to the ClickDetector here if you also want to do more things after the MouseClick connection. If you did, you’d also be destroying the Script itself. The Part would remain intact here.

Well, you both helped me so thank you all.