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

Why doesn't this onClicked function work?

Asked by 9 years ago

Hi,

Here is my script, I wrote it from memory, and then checked it with some previous ones I have made. The only issue I can think of is that I'm trying to turn the canCollide of a Union off.

back=game.Workspace.backdoor1

script.Parent.ClickDetector.MouseClick:connect(function(clicked)
    function onClicked()
        back.CanCollide=false
        back.Transparency=.6
    end
end)

script.Parent.ClickDetector.MouseClick:connect(onClicked)

Thanks!

0
Why do you have a function inside of another function? Lines 4, 7, and 10 are not nessecary. :/ TheeDeathCaster 2368 — 9y

1 answer

Log in to vote
1
Answered by
Redbullusa 1580 Moderation Voter
9 years ago

This script won't work most likely because a function is inside of an anonymous function, with a connection line (for the regular function) outside of the anonymous function. :l

It's either one or the other:

Regular Function

back=game.Workspace.backdoor1

function onClicked()                -- "onClicked" is the name of this function
    back.CanCollide=false
    back.Transparency=.6
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

Anonymous Function

"Anonymous," because no name is assigned to the function

back=game.Workspace.backdoor1

script.Parent.ClickDetector.MouseClick:connect(function ()  -- Where's the name?
    back.CanCollide=false
    back.Transparency=.6
end)

To learn more about functions, visit here.

0
Haha, thanks! I don't know what I was thinking. +1 for you, sir. DrCylonide 158 — 9y
Ad

Answer this question