How to detect click on Billboard?

Hi,
I’m new to Roblox development so I’m sure I have some general misunderstanding on good practices and how things are done… That said, I’ll to click on another player then show a billboard on it (that works) and then click on the billboard (do not work) to open a trading windows. The way I made the detection when clicking a player avoids detecting when clicking on the billboard…
I have test 2 ways none of them are working :

  • adding a MouseButton1Click on the billboard (the textbutton)
  • adding a MouseButton1Click on the general button1Down (the one that detects the click player)

here is my code so you can see what I’m saying!

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local rs = game:GetService('ReplicatedStorage')

local billboardGUIVisible = false
local billboardGUIObject

local function destruirBillboardGUI()
	if billboardGUIObject then
		billboardGUIObject:Destroy()
	end 
	
	billboardGUIVisible = false
end

local function crearBillboardGUI(jugador)
	local billboardGui = Instance.new("BillboardGui")
	billboardGui.Name = "PlayerNameBillboard"
	billboardGui.AlwaysOnTop = true
	billboardGui.Size = UDim2.new(0, 220, 0, 40)
	billboardGui.StudsOffset = Vector3.new(0, 0, 0)
	billboardGui.MaxDistance = 30
	
	local frame = Instance.new("Frame")
	frame.BackgroundColor3 = Color3.new(0.160784, 0.190196, 1)          
	frame.Position = UDim2.new(0, 0, 0, 0) -- Cambia los valores según las coordenadas que desees
	frame.BackgroundTransparency = 0
	frame.Size = UDim2.new(0, 200, 0, 30)
	frame.BorderColor3 = Color3.new(1, 1, 1)
	frame.Parent = billboardGui
	
	local textButton = Instance.new("TextButton")
	textButton.Position = UDim2.new(0, 0, 0, 0) -- Cambia los valores según las coordenadas que desees
	textButton.Name = "tradeButton"
	textButton.Parent = billboardGui
	textButton.BackgroundTransparency = 1
	textButton.Size =  UDim2.new(0, 200, 0, 30)
	textButton.Text = "Trade with " .. jugador.Name 
	textButton.TextColor3 = Color3.new(1, 1, 1)
	textButton.TextScaled = true
	--textLabel.Font = Enum.Font.SourceSansBold
	textButton.TextSize = 8
	textButton.BackgroundTransparency = 1 
	textButton.TextStrokeTransparency = 1
	textButton.ZIndex = 2

	-- TEST 1 -- NOT WORKING

		-- Añadir un evento para detectar los clics en el TextButton
		textButton.MouseButton1Click:Connect(function()
			destruirBillboardGUI()

			local message = Instance.new("Message")
			message.Text = "Has hecho clic en " .. player.Name
			message.Parent = workspace

			wait(3)
			message:Destroy()
		end)

	billboardGui.Parent = jugador.Character.Head
	
	billboardGUIVisible = true
	billboardGUIObject = billboardGui

end


mouse.Button1Down:Connect(function()
	if billboardGUIVisible then
		local tradeButton = billboardGUIObject:WaitForChild("tradeButton")
		
		tradeButton.MouseButton1Down:Connect(function()   -- NOT WORKING NEVER TRIGGED!!! (TEST 2)
			print "CLICKED!!"      -- NOT WORKING NEVER TRIGGED!!!

			local screenGui = game.Players.LocalPlayer:WaitForChild("StarterGui"):WaitForChild("ScreenGui") -- Cambia "ScreenGui" al nombre real de tu ScreenGui
			local frameBuyUser = screenGui:WaitForChild("BuyUserFrame") -- Cambia "Frame" al nombre real de tu Frame

			frameBuyUser.Visible = true

			destruirBillboardGUI()
		end)
		
		destruirBillboardGUI()
	end
	
	local model = mouse.Target:FindFirstAncestorOfClass('Model')
	if model  then
		local clickedPlayer = game.Players:GetPlayerFromCharacter(model)

		if clickedPlayer then
			crearBillboardGUI(clickedPlayer)
		end

	end

end)

How it has to be done? which is the proper way to do what I want?

Thanks

Try using MouseButton1Click instead of MouseButton1Down, also ensure that the referenced object in tradeButton is a TextButton object.