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

Why won't MouseButton1Click work on my TextButton?

I want to make a Title Screen with ScreenGuis, but the "Play" button isn't working. This is the code that I have been trying to tinker with:

wait(0.25)
local Screen = script:WaitForChild('TitleScreenGui') -- ScreenGui
local screen = Screen:Clone() -- ScreenGui that will be put into the PlayerGui

game.Players.playerAdded:connect(function(player)
	local startergui = player:WaitForChild('PlayerGui') -- PlayerGui
	screen.Parent = startergui -- ScreenGui put into PlayerGui
	screen.Enabled = true
end)

screen.Child.Child.Child.MouseButton1Click():connect(function(player)
	-- screen.Child.Child.Child is the "Play" button
	screen.Enabled = false
end)

I searched and read about TextButton and MouseButton1Click many times but I still can't figure it out.

3 comments

1

Are there any errors, which lines? Also, try MouseButton1Down. Not sure if that'll make a difference. Edit-- I think the problem is that you cannot do script.Child unless the object is named "Child". You have to use the actual name of the object.

0

Is the name of the script.Child Actually child? if not that would not work

0

No, it is named "Frame"

1 answer

✓ Accepted answer

There's a syntax error on line 11, MouseButton1Click is not a method, it is an event.

An easy fix is just to replace line 11 with: screen.Child.Child.Child.MouseButton1Click:connect(function(player)

Also, click only fires if the user presses mouse one and lets go of it while the cursor is in the bounds of the TextButton object. If you just want it to fire upon the initial click (which I recommend), use MouseButton1Down:connect().

5 comments

0

Correct, adding on; you could also use a callback.

0

It still doesn't work. Nice try though...

0

Its syntax compiles perfectly; any error is from implementation. Make sure the actual directory the event is being attached to is the proper instance.

0

Sorry, it was my fault. Apparently, you can't use "child" to find the child of the part/gui.

0

Yeah, you have to index it from 'script' or invoke the ':WaitForChild()', 'FindFirstChild()', or ':FindFirstChildOfClass()' methods of Instance.

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