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

Why Isn't my simple click detector script working?

Asked by 6 years ago

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

Log in to vote
2
Answered by 6 years ago
Edited 6 years ago

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

0
Thanks dude! Haha, I should've known :P crystalclay 70 — 6y
0
Glad you understand. Good day~ Zukaazora 30 — 6y
Ad

Answer this question