Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Do I need to have a ClickDetector to trigger a click action?

Asked by 8 years ago

So I want to know do I need a ClickDetector to make click action on a brick?

0
Yes KennySfromTitan 106 — 8y
1
No, you do not need to use ClickDetectors. You can use things such as mouse.Hit, mouse.Target, etc. Thetacah 712 — 8y

3 answers

Log in to vote
0
Answered by 8 years ago

Yes, you need a ClickDetector to make a click work on a brick.

Heres an example that you would include inside a script located under the brick.

script.Parent.ClickDetector.MouseClick:connect(function(playerWhoClicked)
 print("Part was clicked by: " .. playerWhoClicked.Name) --Finds out who clicked it and prints it.
end)
Ad
Log in to vote
0
Answered by 8 years ago

Yes. Here's an example:

button = script.Parent
function ghost()
    button.Transparency = 0.5
end
button.ClickDetector.MouseClick:connect(ghost)
Log in to vote
0
Answered by 8 years ago

Not necessarily, you can do

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Button = script.Parent

Mouse.Button1Down:connect(function()
    if Mouse.Target == Button then
   print("I was clicked")
   end)

It does have its disadvantages though

Answer this question