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

Why Isn't my simple click detector script working?

I am a beginner to Lua. So, for now, this is a simple script for a pandora's box using a click detector. If you click it, it is supposed to print "hello". However, "hello" is not being printed.

function onClicked(playerWhoClicked)
	script.Parent.ClickDetector.MouseClick:connect(onClicked)
	print("hello")
end

1 answer

✓ Accepted answer

You're calling the event line:

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

within the function, when it should actually be after the function instead.

Like this:

function onClicked(playerWhoClicked)
    print("hello")
end

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

I'm not entirely sure what calling the event using that function, inside the function, would do aside from recursive behavior... otherwise, your code is just fine, just a little rearranging is all that is needed

PS: Also cite errors from the output if you get any, they usually help in knowing where your problem lies

2 comments

0

Thanks dude! Haha, I should've known :P

0

Glad you understand. Good day~

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