For detecting a click on a certain block, would I use
function onClicked()
--?
end
or would I use something else, like MouseButtonDown?
For detecting a click on a certain block, would I use
function onClicked()
--?
end
or would I use something else, like MouseButtonDown?
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)
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
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.
2 comments
Beneath the function onClicked part of the script, you would list what the brick is going to do if it is clicked.
Okay, I edited it.