Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

What would I use for detecting a click?

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

function onClicked()
	--?
end

or would I use something else, like MouseButtonDown?

2 comments

0

Beneath the function onClicked part of the script, you would list what the brick is going to do if it is clicked.

0

Okay, I edited it.

3 answers

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

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)

1 comment

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.

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

1 comment

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.