Remote event and function

I have a localscript that sometimes tells a serverscript to do some stuff. This localscript also sometimes requests something from that serverscript. The localscript and serverscript look something like this:
Localscript:

local Functions = {
    Function1 = function()
        RemoteFunction:InvokeServer(args)
    end,
    Function2 = function()
        local Result = RemoteFunction:InvokeServer(args)
    end
}

Bindable.Event:Connect(function(FunctionName)
    Functions[FunctionName](args)
end)

ServerScript

local Functions = {
    Function1 = function()
        --do some stuff
    end

    Function2 = function()
        --do some stuff
        return Result
    end
}

RemoteFunction.OnServerInvoke = function(FunctionName)
    Function[FunctionName](args)
end

So currently the LocalScript is firing a remotefunction always even though it doesn’t always want something back from the server. My question is: is it better to have a remoteEvent that tells the server to do something and have the remotefunction only if the LocalScript wants some information back? And if so why? If you have any questions feel free to ask.

RemoteFunction:InvokeClient isn’t recommended. You can fire a remote event to the client though

That is not what I asked. I’m sorry if I was not clear, but my question was if I should use a separate remoteEvent for one way communication from the client to the server or if it is fine to only have a remotefunction that invokes the server while not always needing something back from the server.

If you are fine with the script yielding for some time (mostly based on ping) even if there’s no returned value, you can keep it as a RemoteFunction, if you don’t want this to happen - split the functions in 2 types: ones that return something and ones that don’t, use the RemoteFunction for the ones that return something, and a RemoteEvent for the ones that don’t.
Also, RemoteFunctions will error the client too if an error happens on the server after it has been invoked, the same goes for the server erroring if a client does after doing InvokeClient().

1 Like