TextButton in BillboardGui not firing MouseButton1Click event

I may be doing something wrong, but I can’t seem to get a TextButton in a BillboardGui to fire the MouseButton1Click event.

Clip:

Code:

script.Parent.MouseButton1Click:Connect(function()
   print("success")
end)

Hierarchy:

uh

Place FIle:

TextButton not firing MouseButton1Click event in BillboardGui.rbxl (19.2 KB)

1 Like

LocalScripts don’t run under workspace.

2 Likes

Maybe the best possible solution is to place the script in StarterPlayerScripts and do the following:

workspace:WaitForChild("Part").BillboardGui.Frame.TextButton.MouseButton1Click:Connect(function()
   print("success")
end)

This is indeed client-sided.

1 Like

Thanks for the help; my mistake. However, this error occurs even if the localscript is in one of those approved locations.

New Code:

game.Workspace:WaitForChild("Part"):WaitForChild("BillboardGui"):WaitForChild("Frame"):WaitForChild("TextButton").MouseButton1Click:Connect(function()
    print("success")
    end)

New Hierarchy:

uh%202

New Place File:

TextButton not firing MouseButton1Click event in BillboardGui.rbxl (19.2 KB)

It appears that TextButtons don’t register clicks when in a BillboardGui. (Bug report?)

This works fine if you use ScreenGuis and position them over the part.

Place File: working.rbxl (17.4 KB)

1 Like

I believe this can be fixed by parenting the BillboardGui to the StarterGui, and setting the ‘Adornee’ property to workspace.Part. (this is probably the easiest solution)

For example

local Billboard = game.Players.LocalPlayer:WaitForChild(“PlayerGui”):WaitForChild(“BillboardGui”)

Billboard.Adornee = workspace:WaitForChild(“Part”)

Billboard.Textbutton.MouseButton1Click:connect(function()
print(“success”)
end)

12 Likes

If I recall correctly, BillboardGuis and SurfaceGuis only work when parented to the StarterGui.
(any functioning gui elements inside of them, at least)

(see this)
The top button doesn’t even seem to register when the mouse enters the gui, you can see that because it doesn’t make the button’s background go darker.

The bottom button is parented to the StarterGui and is adorned to the part. The button registers when the mouse enters and when I click.

I’m pretty sure it said this on the wiki although I can’t check because the pages won’t load for me.

(edit)
Furthermore, the MouseEnter event doesn’t fire on the button that isn’t in StarterGui. It seems any GUI objects that aren’t in the StarterGui are simply cosmetic.

1 Like

This is actually unrelated. A button with the property AutoButtonColor as false will not darken the button upon hover as well.

2 Likes