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

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

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

1 comment

0

Simple answer --> No

1 answer

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)

2 comments

0

Thank you! :D

0

Np, can you accept the answer?

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