How can I reconnect a function that has been disconnected?

Well, basically I want to reconnect the first function shown in the following script, it disconnects so that it does not interrupt the FocusLost of a textBox, but in the end it no longer works again when disconnected

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ChosePlayerDropEvent = ReplicatedStorage:WaitForChild("PlayerListSelectionDrop") 

local TextBox = script.Parent:FindFirstChild("TextBox")
local Players = game:GetService("Players")
local RealName = script.Parent:FindFirstChild("RealName")
local ImagePlayer = script.Parent:FindFirstChild("PlayerImage")

local Main = script.Parent.Parent.Parent

local Player1 = Main:FindFirstChild("Player1")
local Player2 = Main:FindFirstChild("Player2")
local Player3 = Main:FindFirstChild("Player3")
local Player4 = Main:FindFirstChild("Player4")
local Player5 = Main:FindFirstChild("Player5")

local LocalPlayer = game.Players.LocalPlayer

local connection

local function TextConnection()
	RealName.Text = "Presiona la tecla enter."

	if EnterPressed then --This is a bool, so it'll be true or false
		for _, players in pairs (Players:GetChildren()) do
			if not (Player1.Value == TextBox.Text ) and  
				not (Player2.Value == TextBox.Text ) and  
				not (Player3.Value == TextBox.Text ) and  
				not (Player4.Value == TextBox.Text ) and  
				not (Player5.Value == TextBox.Text ) then  

				if (TextBox.Text == LocalPlayer.Name) or (TextBox.Text == LocalPlayer.DisplayName) then
					RealName.Text = "No puedes ponerte a ti mismo."
					TextBox.Text = ""
					RealName.Text = "@(Nombre del jugador)"
					Player1.Value ="N/A"
					ImagePlayer.Image = ""

				elseif (TextBox.Text == players.Name) or (TextBox.Text == players.DisplayName) then

					local UserId = players.UserId
					local thumbType = Enum.ThumbnailType.HeadShot
					local thumbSize = Enum.ThumbnailSize.Size420x420
					local content, isReady = Players:GetUserThumbnailAsync(UserId, thumbType, thumbSize)

					ImagePlayer.Image = content
					Player1.Value = players.Name
					RealName.Text = "@".. players.Name

				elseif (TextBox.Text ~= Players.Name) or (TextBox.Text ~= players.DisplayName) then

					RealName.Text = "No se encontro el jugador."
					RealName.Text = "@(Nombre del jugador)"
					Player1.Value ="N/A"
					ImagePlayer.Image = ""
				elseif TextBox.Text == "" then
					RealName.Text = "@(Nombre del jugador)"
					Player1.Value ="N/A"
					ImagePlayer.Image = ""
connection = TextBox:GetPropertyChangedSignal("Text"):Connect(TextConnection)

(At the moment it is in Spanish since it is my native language, then I will translate it into English)

You can reconnect it like you just did here:

connection = TextBox:GetPropertyChangedSignal("Text"):Connect(TextConnection)
1 Like

I guess it should work but it just doesn’t work anymore after that

I’m also wondering why you’d need to disconnect the event, there is not really any reason to in this case.
You should only disconnect events that are no longer being used.

1 Like