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.

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

Yes. Here's an example:

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

Not necessarily, you can do

1local Player = game.Players.LocalPlayer
2local Mouse = Player:GetMouse()
3local Button = script.Parent
4 
5Mouse.Button1Down:connect(function()
6    if Mouse.Target == Button then
7   print("I was clicked")
8   end)

It does have its disadvantages though

Answer this question