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

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

Asked by 5 years ago
Edited 5 years ago

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

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

TeleportationButtons.ScreenGui.First.Activated:Connect(FirstOnClick())
0
This is weird, try to recode it RadiatedExodus 41 — 5y

2 answers

Log in to vote
1
Answered by 5 years ago

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)
Ad
Log in to vote
1
Answered by
gloveshun 119
5 years ago

try out this:

local function Print(Val)
    print(Val)
end

TeleportationButtons.ScreenGui.First.Activated:Connect(Print("Clicked"))
0
Why does the output say that i tried to print a nil value? AndriusTheGreat 140 — 5y
0
I will remember to accept your answer :). AndriusTheGreat 140 — 5y
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. royaltoe 5144 — 5y
1
umm gloveshun 119 — 5y

Answer this question