Trying to convert a ClickDetector script into a TextButton script

How would I convert this code to work when a “TextButton” is clicked, I have started using SurfaceGuis, so this is something important for me to achieve.

local ToolNames = {"Taser"}
local Storage = game:GetService("ServerStorage")


local Part = script.Parent
local ClickDetector = Part:WaitForChild("ClickDetector")

ClickDetector.MouseClick:connect(function(Player)
	if Player and Player.Character then
		local Backpack = Player:WaitForChild("Backpack")
		for i = 1, #ToolNames do
			local Tool = Storage:FindFirstChild(ToolNames[i])
			if Tool then
			wait(10)Tool:clone().Parent = Backpack
			end
		end
	end
end)
1 Like

Just use this example:

local txtbutton = -- path to text button
-- other variables, etc

txtbutton.MouseButton1Click:Connect(function()
    -- your code
end)
2 Likes