Just for some context, I use remote events all the time. I love them, but I’ve never had to or seen a need to send information from the client to the server and back aswell. Usually for almost everything I’ve done remote events have been the way to go.
And it’s not like I haven’t made complicated systems yet either.
I’ve been scripting for 9 months and I think there was only ONE time where I may’ve POSSIBLY needed to use a remote function, and I’m pretty sure I was able to switch to a remote event instead because I realised there was another way to do what I wanted.
Server → Client Remote functions aren’t used too often because of vulnerability (you can patch it, but the data can still be iffy)
Client → Server Remote functions are more widely used because they’re more secure and you can guarantee the data will likely be correct (since the server is returning it).
If you just need to trigger something to happen, then you won’t need to use RemoteFunctions, but when you need specific data held on the server to be transferred to the client, you’ll find them much more useful.
Definitely not, remote functions shouldn’t be needed very often, if at all. And since they can’t really transfer un replicated data, if it’s an instance you might as well yield using WaitForChild.
Another thing too, RemoteFunctions are asynchronous, yet they also are yielded, so it creates more complexity, Remote Events are also more secure depending on use.
The example you provided is something that works with RemoteEvents; you aren’t returning anything to the client or the server.
Think about loading a webpage: your client sends a request to the server for the webcontent and the server returns the information so the client can load and display it, that’s essentially what a RemoteFunction is
Both Remote Functions and Remote Events are Asynchronous, because obviously you don’t want to halt the server.
However, RemoteFunctions are Asynchronous on the Server, but on the Client they are Synchronous in behavior, since the client will yield until a response is provided.
Ex:
--- Server Script
function RemoteHandler()
task.wait(2)
return "Hi"
end
--- Local Script
local RemoteFuncPromise = remoteFunc:InvokeServer()
-- RemoteFuncPromise -> returns Hi after two seconds
--- Server Script
function RemoteEventHandler()
task.wait(2)
print("Hi") -- Prints hi after 2 seconds
end
--- Local Script
RemoteEvent:FireServer()
-- Code continues executing, will not wait for the server.
The info the server returns is more secure because the developer is the one managing what is returned from the server side (assuming you’re coding everything correctly), whereas InvokeClient isn’t secure because the client can be tampered with and return anything
With this information, you may actually need to use a Remote Func, maybe because you want to ensure that the data/job/task or whatever your sending to the server is fully complete, this allows you to yield for the server and detect when it’s done something.
I think this is the correct answer, also an annoying feature of remote functions is the yielding. It may be slightly more secure, but let’s say you want to do something whilst its yielding. Now you have to use task.spawn/coroutines which is really a problem (just a personal grudge)
A remote event sanity check should usually be enough, returning shouldn’t really be necessary imo.
I’m confused, what do you mean? The server’s information is coming from the server. If you’re talking about how the client uses that information, that’s not exactly what I was talking about; I was talking about the info itself