How to check if a textbutton is pressed if its auto generated by "Instance.new"

So, in table i have the word products. I am checking if there’s a name for it. If so then i want to generate a button that makes a new textlable. I am using the method but there is no response, I’d checked if it would print “HIIIII” But it didn’t respond. Code is below.

for _, Products in pairs(Config.Products) do
	local TextButton = Instance.new("TextButton")
	TextButton.BorderSizePixel = 0
	TextButton.BackgroundTransparency = 0
	TextButton.BackgroundColor3 = Color3.new(1, 1, 1)
	TextButton.Font = Enum.Font.Ubuntu
	TextButton.TextSize = 40
	TextButton.Text = Products["Name"]
	TextButton.Size = UDim2.new(0, 75,0, 75)
	TextButton.ZIndex = 2
	TextButton.AutoLocalize = true
	TextButton.Parent = choosingFrame
	TextButton.MouseButton1Down:Connect(function()
		local ProductLable = Instance.new("TextLabel", CartFrame)
		print("HIIII")
		UIListGrid.Padding = UDim.new(0, 10)
		ProductLable.BorderSizePixel = 0
		ProductLable.BackgroundTransparency = 1
		ProductLable.Position = UDim2.new(0,0, 0,0)
		ProductLable.Size = UDim2.new(0,151, 0,28)
		ProductLable.Font = Enum.Font.Ubuntu
		ProductLable.TextSize = 25
		ProductLable.Text = Products["Name"]
	end)
end

I am unsure if there’s an actual way to do this, But I’d do a sneaky and just add a value or just an empty object in the button called ‘instanced’ and findfirstchild that when looking for it. Not the perfect solution but it works.

That should absolutely work. Any output?

I’ve already made a video, It not really responding at all.

I can send like a screen shot of my outpout

I found a solution, i needed to add a remote event, to power it.

for _, Products in pairs(Config.Products) do
	local TextButton = Instance.new("TextButton")
	TextButton.BorderSizePixel = 0
	TextButton.BackgroundTransparency = 0
	TextButton.BackgroundColor3 = Color3.new(1, 1, 1)
	TextButton.Font = Enum.Font.Ubuntu
	TextButton.TextSize = 40
	TextButton.Text = Products["Name"]
	TextButton.Size = UDim2.new(0, 75,0, 75)
	TextButton.ZIndex = 2
	TextButton.AutoLocalize = true
	TextButton.Parent = choosingFrame
	TextButton.MouseButton1Click:Connect(function()
		local ProductLable = Instance.new("TextLabel")
		UIListGrid.Padding = UDim.new(0, 10)
		ProductLable.BorderSizePixel = 0
		ProductLable.BackgroundTransparency = 1
		ProductLable.Position = UDim2.new(0,0, 0,0)
		ProductLable.Size = UDim2.new(0,151, 0,28)
		ProductLable.Font = Enum.Font.Ubuntu
		ProductLable.TextSize = 25
		ProductLable.Text = Products["Name"]
		ProductLable.Parent = CartFrame
	end)
end

Try this, I changed the event (from button down to button click) and I’ve parented the created instance after all of the properties have been set.

I’ve already tried that but its fixed. Thank for your help tho :slight_smile: