Making an onClicked script
Intro
This is a FAQ that will teach you how to make a simple onClicked script. What is onClicked? I'll explain...
What is onClicked?
Not long ago, Roblox released a new feature known as a Click Detector. If you put it inside a brick it will detect when it is clicked. Duh. This FAQ will explain how to put it to use.
Getting Started
First things first, you have to put the ClickDetector inside the brick. Click on the brick, then click on 'Insert" on the toolbar and then click on "Object". Then look for "Click Detector" in the window that pops up. Voila, you now have your Click Detector. Now, put in a script.
The Script
Finally, the scripting! Here is the first part:
function onClicked()
This tells the game to set off the function when the brick is clicked on. Next we have to put in the function (feel free to change this part if you want)
local x = (math.random(0,10) * 0.1) local y = (math.random(0,10) * 0.1) local z = (math.random(0,10) * 0.1) script.Parent.Color = Color3.new (x, y, z)
This tells the game to change the block's color to a random color.
Finally, you need to 'connect' the script.
script.Parent.ClickDetector.MouseClick:connect(onClicked)
And now you're done! The finished script should look like this:
function onClicked() local x = (math.random(0,10) * 0.1) local y = (math.random(0,10) * 0.1) local z = (math.random(0,10) * 0.1) script.Parent.Color = Color3.new (x, y, z) end script.Parent.ClickDetector.MouseClick:connect(onClicked)
Other Stuff
Nothing yet... I may add some more specific stuff here in the future, like button operated elevators, etc.
--superfroggy