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

How to make a text button that creates another text button?

Asked by
micmnm4 18
7 years ago

How to make a text button that creates another text button?

0
Instance.new("TextButton"); TextButtonNameHere.MouseButton1Click:connect(function() There are some hints. Try to attempt to do so on own. This isn't a request site. Vingam_Securis 213 — 7y

1 answer

Log in to vote
0
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
7 years ago

You need to use the Instance.new function in order to create ROBLOX Objects (or Instances) from Lua code. Aftering 'Instancing' it, you can code its properties and listen to its events like any other ROBLOX Object:

local button = script.Parent
local newButton = nil

button.MouseButton1Click:connect(function()
    if newButton then newButton:Destroy() end

    local random = math.floor(math.random()*100)

    newButton = Instance.new("TextButton")
    newButton.Size = UDim2.new(0, 500, 0, 250)
    newButton.Text = "Another example of setting a property"
    newButton.Parent = script.Parent.Parent

    newButton.MouseButton1Click:connect(function()
        print("New Button Clicked! " .. random)
    end)

end)
Ad

Answer this question