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

Why won't MouseButton1Click work on my TextButton?

Asked by 8 years ago

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.

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. TheLuckyZ 24 — 8y
0
Is the name of the script.Child Actually child? if not that would not work pluginfactory 463 — 8y
0
No, it is named "Frame" marioblast1244 113 — 8y

1 answer

Log in to vote
1
Answered by 8 years ago

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().

0
Correct, adding on; you could also use a callback. JamesLWalker 297 — 8y
0
It still doesn't work. Nice try though... marioblast1244 113 — 8y
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. TheEdgyDev 50 — 8y
0
Sorry, it was my fault. Apparently, you can't use "child" to find the child of the part/gui. marioblast1244 113 — 8y
0
Yeah, you have to index it from 'script' or invoke the `':WaitForChild()`', '`FindFirstChild()`', or '`:FindFirstChildOfClass()`' methods of Instance. TheEdgyDev 50 — 8y
Ad

Answer this question