RemoteFunction, is this a bad practise?

Hi guys! I’m Adrian, a 29 year old Roblox Developer - started May 31st and am learning a lot!

I have a question in regards to how I am using RemoteFunctions from Local to Server. Here is an example:

module.SendTradeRequest = function(tradedPlayer, outgoingTradesFrame)
	
	local result = sendTradeRequestRemoteFunction:InvokeServer(tradedPlayer)
	if result == "Trade request successfully sent." then
		outgoingTradesFrame.Decline.Visible = true
		outgoingTradesFrame.Decline.Active = true
		outgoingTradesFrame.Send.Visible = false
		outgoingTradesFrame.Send.Active = false
		outgoingTradesFrame.Timer.Visible = true
		
		outgoingTradesFrame.TimerScript:SetAttribute("time", 59)
		outgoingTradesFrame.TimerScript.Enabled = true
	end
end

I am getting mixed answers to this question, hopefully you can help me understand this a bit better, and teach me what is the best practise.

After the line

local result = sendTradeRequestRemoteFunction:InvokeServer(tradedPlayer)

I am checking what the result was:

if result == "Trade request successfully sent." then

Will this if statement sometimes run before the server has had a chance to respond, resulting in result being equal to nil ? Or will the Local script wait for the server to return something for result to hold, before proceeding with the if statement?

If this method is wrong, my best guess would be to stop using RemoteFunctions and instead convert this into 2x RemoteEvents - one for firing from Server to Local, and one from Local to Server that responds - but then comes the trouble/extra work of negating any exploits that this open up for :smiley:

Thanks for any insights! Hope you have an awesome day :sunglasses:

1 Like

No, invoking any kind of […]Function will yield the code until it gets a response. It doesn’t drop, that’s why the server invoking a client should be carefully handled.

2 Likes

Thank you for the quick response!

Am I understanding you correctly - the Client’s if statement will wait for the Server to respond to the Client and set my result variable before proceeding with the if statement? And you are also saying that we should be careful with invoking the server from a client - is this because if the player’s connection is poor to the Server, there might be a serious delay before the Client gets a response from the Server, and the code will not continue to run until that happens - or are you referring to exploitation as the reason why we should be careful?

1 Like

Yes, the client code will wait for a response from InvokeServer before the code continues.

Also, the thing to be careful of with InvokeServer, is only because there might be a delay, and considering the script is paused, while waiting for a response, this might cause a bottleneck in your code.

You should never use InvokeClient, because the serve could wait for a client that is disconnected.

Exploiting is an issue with all remote events or remote functions.
Always do critical checks on the server.

3 Likes

Thank you so much for the clarification @SelDraken! :slight_smile: Hope you have a great continuation of your day.

2 Likes

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