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

i did this tap to change to random color and it didnt work. what did i do wrong?

local click = script.Parent.ClickDetector

function onClick()
    script.Parent.BrickColor = BrickColor.random()
end

click.MouseClick:connect(onClick)

and i put it in under click detecter, as the click detecter is the parent of this script. and the parent of that click detecter is a block. what did i do wrong?

2 answers

✓ Accepted answer

Firstly, I'd like to introduce you to anonymous functions.

They're used fairly frequently, and can shorten code, and make it look pretty :).

In your case, the anonymous function will look like this;

local click = script.Parent.ClickDetector

click.MouseClick:connect(function() --You use the event, and ":connect(function()" after it.
	script.Parent.BrickColor = BrickColor.random()
end) --The end for the anonymous function must have a ")" at the end of it.

2 comments

0

i did this and it didnt work. do i put the script under the click detecter as the click detecter was the parent. and a block was the parent of the click detecter

0

oh gg it works

Your problem is that you said the click detector is the scripts parent. The way your script is scripted, the part should be the parent.

3 comments

0

oh, ok. thanks

0

it didnt work! i deleted the click detecter and added the script to the block an it didnt work.

0

Sigh I never said to delete the click detector.

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