Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 7 years ago
Edited 7 years ago
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

Log in to vote
0
Answered by 7 years ago

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.
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 AndyTheScriptKiddie6 10 — 7y
0
oh gg it works AndyTheScriptKiddie6 10 — 7y
Ad
Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

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.

0
oh, ok. thanks AndyTheScriptKiddie6 10 — 7y
0
it didnt work! i deleted the click detecter and added the script to the block an it didnt work. AndyTheScriptKiddie6 10 — 7y
0
*Sigh* I never said to delete the click detector. FrostTaco 90 — 7y

Answer this question