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

Why does it print ("ButtonClicked"), before i have pressed the button?

Why does it print "ButtonClicked" before i have pressed the button?

local function FirstOnClick()
	print("ButtonClicked")
end

TeleportationButtons.ScreenGui.First.Activated:Connect(FirstOnClick())

1 comment

0

This is weird, try to recode it

2 answers

✓ Accepted answer

When you want to use events you should pass a REFERENCE to the function, by adding parenthesis you invoke the function instead of referencing it:

Wrong:

TeleportationButtons.ScreenGui.First.Activated:Connect(FirstOnClick())

Correct:

TeleportationButtons.ScreenGui.First.Activated:Connect(FirstOnClick)

try out this:

local function Print(Val)
    print(Val)
end

TeleportationButtons.ScreenGui.First.Activated:Connect(Print("Clicked"))

4 comments

0

Why does the output say that i tried to print a nil value?

0

I will remember to accept your answer :).

1

The reason that was happening was because you added the parenthesis on line 5. Only include "FirstOnClick" if you do not have anything in the parenthesis and it should work.

1

umm

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