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

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

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

1 comment

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.

1 answer

✓ Accepted answer

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)

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