Question regarding ":Disconnect()"

I’m using a RemoteEvent to send information from a tool to the server, but I want it to disconnect the function if it hits a certain criteria when running through the function.

Can I use disconnect when Connecting it directly?

I.E.

Event.OnServerEvent:Connect(function()

--can i disconnect this?

end)

EDIT: I’m completely aware that you can use :Disconnect() on a normal function when it’s connected via an event, I’m wondering if you can disconnect it with the function being structured like shown above.

You can, the only thing is that you would need to declare a variable before assigning to it.

local connection
connection = event.OnServerEvent:Connect(function()
    connection:Disconnect()
end)

PS if you’re only listening for the signal to be fired one time, you can use signal:Once.

2 Likes

You can try this setup.

local connection

connection = Event.OnServerEvent:Connect(function()

connection:Disconnect()

end)
1 Like

Much appreciate, thank you guys a ton!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.