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?
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.
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.