Remote function help

So when using remote events you can save the connection of the OnServerEvent signal so you can disconnect it when you want, E.g:

connections['EventTriggerd'] = Event.OnServerEvent:Connect(function(Player:Player,A,B,C,D,E,F,G,H,I,J)

How can I do this with remote functions? I tried this but it doesnt work due to the two equal signs and what not:

connections['EventTriggerd'] = Event.OnServerInvoke = function(Player:Player,A,B,C,D,E,F,G,H,I,J)

for RemoteFunctions, the function just by itself should be the variable, and then you bind the function to the RemoteFunction later.

local function TriggeredFunc(message)
    print(message)
end

Event.OnServerInvoke = TriggeredFunc

The Event.OnServerInvoke isn’t a connection really, it’s more rigid and kind of its own variable in and of itself, needing an equals sign to be set up for receiving input, which is why it can’t really be stored in memory.

So I could probably just set it to nil then?

If you want to change it/disconnect it later, it’s much better to use RemoteEvents imo.

Not really, Remote functions are just better in my situation as I need to pass info back in force

There’s no way to store the connected function as a variable in itself.

If you want to reference it/change it later, you’d simply have to give it another thread/function using the equals sign when that needs doing

local function newFunction(...)

end

function ChangeEvent()
    RemoteFunction.OnServerInvoke = newFunction
end

I’d like to add (to further follow your code-structure) that this can also be done as below, without having to deliberately initiate a separate function to later assign to the connections table.

connections['EventTriggered'] = function(Player:Player,A,B,C,D,E,F,G,H,I,J)
	-- Code
end

Event.OnServerInvoke = connections['EventTriggered']

Lastly, when assigning the Invoke callback Event.OnServerInvoke = functionName(no, parametersNeeded, here), you do not need to parse the function’s parameters alongwith it as the function call is all that’s needed, and the rest is automatically parsed as the function call proceeds.

1 Like

You still haven’t renamed the variable oh god

Anyways, it’s a property and does not return anything else as it’s not a ScriptConnection! You don’t need to store it as there is no disconnection either. Treat Event.OnServerInvoke as a property, not a method. If you ever want to “disconnect” it, just set Event.OnServerInvoke to nil.

2 Likes

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