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

What would I use for detecting a click?

Asked by 10 years ago

For detecting a click on a certain block, would I use

function onClicked()
    --?
end

or would I use something else, like MouseButtonDown?

0
Beneath the function onClicked part of the script, you would list what the brick is going to do if it is clicked. bloonblaster2000 55 — 10y
0
Okay, I edited it. bloonblaster2000 55 — 10y

3 answers

Log in to vote
0
Answered by 10 years ago

You'd put a ClickDetector in the brick and put a script inside the detector going something like this:

script.Parent.MouseClick:connect(function()
    print(script.Parent.Parent.Name.." was clicked!")
end)

For more information go to the Wiki Page

Ad
Log in to vote
0
Answered by 10 years ago

It would go something like this, for example:

H = game.Workspace.Part

function Clicked(Part)
H.Transparency = 1
wait(5)
H.Transparency = 0
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)
0
You have the function on the top as onClick and the function on the bottom as onClicked. You may want to revise your script. CardboardRocks 215 — 10y
Log in to vote
0
Answered by
Xoqex 75
10 years ago

Well, what you have so far:

function onClicked()
    --?
end

That by itself is not really a function, onClicked is just a name. You could do function DatClickBro() or anything else, as that is just the name of the function. What makes it work is CALLING the function, some people add it to the end and some put it right at the front.

So first thing you need to do is make sure there is a click detector in the brick, then add a script to the brick.

Then do something like this:

function onClicked() --OnClicked is the name of the function
script.Parent.Color = math.random()--If this doesn't make the color random then take the math. out, I'm not 100% sure if it's math.random() or random() for this type of thing since it's not a number value.
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)--This is calling the function

0
Correct: script.Parent.BrickColor = BrickColor.Random() --I know for a lot of things it is s"random" But this is what comes to a draw on that. fireboltofdeath 635 — 10y

Answer this question