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

Does a script need to be a child of a button for connect(function) to work?

Asked by 6 years ago

This works fine:

button = script.parent

function click()
    print("hello")
end

button.MouseButton1Click:connect(click)

but this doesn't work?

function click()
    print("hello")
end

game.StarterGui.ScreenGui.TextButton.MouseButton1Click:connect(click)

This doesn't work too...

game.StarterGui.ScreenGui.TextButton.MouseButton1Click:connect(function (click)
    print("hello")
end)

in examples 2 and 3 script was not a child of the button TY

0
Simple answer --> No User#20388 0 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

Simple answer --> No

So.. what's the problem then? --> Answer: You're forgetting that startergui gets cloned to the playergui, the startergui buttons will never get clicked!

Also, remember your scripts need to be local scripts inside client areas.

(The best way to do what you want to do is using script.Parent.Parent.Button for example, as these won't change if it gets cloned)

0
Thank you! :D MixedEffects 0 — 6y
0
Np, can you accept the answer? User#20388 0 — 6y
Ad

Answer this question