Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why doesn't this onClicked function work?

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!

1 comment

0

Why do you have a function inside of another function? Lines 4, 7, and 10 are not nessecary. :/

1 answer

✓ Accepted answer

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.

1 comment

0

Haha, thanks! I don't know what I was thinking. +1 for you, sir.

This discussion is preserved as it was. New answers, comments, and votes are closed.