📜  clickdetector player roblox - Lua 代码示例

📅  最后修改于: 2022-03-11 14:54:55.195000             🧑  作者: Mango

代码示例2
-- 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!