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

Clicking a TextButton in a BillboardGui won't work?

I'm trying to make it so that if you click the TextButton then it will print "Clicked", but it doesn't work. Here is the code:

function ToggleGui(Part)
	local a = Instance.new("BillboardGui",Part)
	a.Size = UDim2.new(1,0,1,0)
	a.StudsOffset = Vector3.new(0,0,0)
	a.AlwaysOnTop = true
	a.Active = true
	a.Adornee = Part
	a.Name = "Gui"
	
	local s = Instance.new("TextButton",a)
	s.BackgroundColor3 = BrickColor.new("Light stone grey").Color
	s.BackgroundTransparency = .7
	s.BorderSizePixel = 0
	s.Size = UDim2.new(1,0,1,0)
	s.Position = UDim2.new(0,0,0,0)
	s.Active = true
	s.Font = "Legacy"
	s.Text = "Use"
	s.TextColor3 = BrickColor.new("Institutional white").Color
	s.TextStrokeTransparency = 0
	s.TextWrapped = true
	s.TextScaled = true
	
	s.MouseButton1Down:connect(function()
		print("Clicked")
	end)
end

Everything shows up, but the TextButton just wont work. There are no errors in the Output. I've tried using MouseEnter, MouseButton2Down, moving the StudsOffset, moving the GUI into PlayerGui, and changing Sizes and Positions, though it still doesn't work. Is it just that there's something wrong with the Part that I place it in or is there something wrong with the code?

1 comment

0

Tried switching to an ImageButton, the events still don't fire.

1 answer

"Everything shows up, but the TextButton just wont work." I don't understand what you mean, but this is your problem:

s.MouseButton1Down:Connect(function()

The line that it's at is only correct if you want it to print "Clicked". Otherwise it will do nothing else than that. Here's the solution:

function ToggleGui(Part)
    a = Instance.new("BillboardGui",Workspace.Part)
    a.Size = UDim2.new(1,0,1,0)
    a.StudsOffset = Vector3.new(0,0,0)
    a.AlwaysOnTop = true
    a.Active = true
    a.Adornee = Part
    a.Name = "Gui"

    s = Instance.new("TextButton",a)
    s.BackgroundColor3 = BrickColor.new("Light stone grey").Color
    s.BackgroundTransparency = .7
    s.BorderSizePixel = 0
    s.Size = UDim2.new(1,0,1,0)
    s.Position = UDim2.new(0,0,0,0)
    s.Active = true
    s.Font = "Legacy"
    s.Text = "Use"
    s.TextColor3 = BrickColor.new("Institutional white").Color
    s.TextStrokeTransparency = 0
    s.TextWrapped = true
    s.TextScaled = true

        print("Clicked")
    end)
end
s.MouseButton1Down:connect(ToggleGui)

2 comments

0

There's many more problems you have. I'll fix them.

0

I wanted the TextButton to be able to be clicked, though when I click it, nothing happens.

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