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

Is this correct?

Asked by 10 years ago
local brick = Workspace.InvisibleBrick

brick.Touched:connect(ontouch)
function onTouch(Part)
brick.Transparency = 1 
wait(1) 
brick.Transparency = 0
end

2 answers

Log in to vote
2
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
10 years ago

You should really test this on your own and use the Output window in Studio to catch any bugs.

In this case, there are two:

When you try to connect that function, 'ontouch' is not defined, since you define the function as 'onTouch'. However, at that point in the script, 'onTouch' isn't defined either.

To fix this, move the connection line to below the function definition.

local brick = Workspace.InvisibleBrick

function onTouch(Part)
    brick.Transparency = 1 
    wait(1) 
    brick.Transparency = 0
end
brick.Touched:connect(onTouch)

In case you didn't already know, you don't have to name functions anything specific for them to work for certain events. A better name for this function would be "flickerPart" as that describes what it does.

Also, you may have seen connection lines above the body of the functions that connect to, but if you look closely, those functions are never explicitly defined to a variable. These functions are called Anonymous Functions.

Ad
Log in to vote
0
Answered by 10 years ago

On your connection line you forgot to capitalize the "T" in "onTouch"

local brick = Workspace.InvisibleBrick

brick.Touched:connect(onTouch) <-----HERE
function onTouch(Part)
brick.Transparency = 1 
wait(1) 
brick.Transparency = 0
end


Answer this question