local brick = Workspace.InvisibleBrick brick.Touched:connect(onTouch) function onTouch(Part) brick.Transparency = 1 wait(1) brick.Transparency = 0 end
Scripts execute top to bottom.
So, when we get to line 3, it looks for onTouch
, but there isn't anything called onTouch
, since it hasn't been made yet. Variables that have not yet been defined are nil
, which is where that error comes from.
Move the connection line below the function definition.
You're trying to connect an event to a nil value. On line 03, the onTouch function does not exist. It only exists after line 04, because that's when you create the function. This can be fixed easily by placing the connection line after the function is created.
function onTouch(Part) --stuff end brick.Touched:connect(onTouch)