ClickDetector Player Roblox

-- A click detector is a special instance that gives you the ability to click a solid object..
-- Lets say you had a part, you put a clickdetector in it! That's great, now..
-- Let's put a script inside the click detector..When we do that, let's write this:

local Click = script.Parent --(the script is the child of the click detector, so calling for the
-- parent of the script [WHICH IS THE CLICKDETECTOR] will tell the script to get the click detector!)

local part = Click.Parent --(Assuming youve added the clickdetector inside the part, we can just
-- call the clickdetector, and also find the parent which SHOULD be the part.

local function printmessage()
  print("Hello, you clicked me!")
  part:Destroy() -- deletes the part
end -- This function can only run if you call it, we will get to that in a moment!

Click.MouseClick:Connect(printmessage) -- "If the parent of the clickdetector (part) is clicked, then
-- call the function..

--And that's the basic jist of clickdetector, hope it helps!
Opal