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

Clicking a TextButton in a BillboardGui won't work?

Asked by 10 years ago

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?

0
Tried switching to an ImageButton, the events still don't fire. GloriousOromis 10 — 10y

1 answer

Log in to vote
1
Answered by
Irvene 5
10 years ago

"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)
0
There's many more problems you have. I'll fix them. Irvene 5 — 10y
0
I wanted the TextButton to be able to be clicked, though when I click it, nothing happens. GloriousOromis 10 — 10y
Ad

Answer this question