RemoteEvents or RemoteFunctions?

My goal would be “power” games like blox fruits and other games of this kind.

But I don’t know which one I should use. I’ve been using Roblox Studio for a while and I’ve always done research on the subject, but I’ve never really gotten to the bottom of my question.

My goal is for the player to be able to start the skill and finish it with as little delay as possible and for the server to be able to send it to everyone with less delay.

Currently I’m using RemoteFunction to make skills, but there are delays that RemoteEvent wouldn’t have… I want to know your opinions.

My script base:

Client(Replicator)

local rep = game:GetService("ReplicatedStorage")

local Server = rep.Eventos.Server

local Effects = {}

for _, Module in pairs(script:GetDescendants()) do
	if Module:IsA("ModuleScript") then
		Effects[Module.Name] = require(Module)
		Module:Destroy()
               -- ModuleScript with parts, particles and all effects!
	end
end

Server.OnClientInvoke = function(Skill, Action, Data)
	Effects[Skill][Action](Data)
end

ServerHandler (Damage and perm effects)

local rep = game:GetService("ReplicatedStorage")

local Server = rep.Eventos.Server

local MAXDIST = 300

local Sets = {}
for i, Module in pairs(script:GetDescendants()) do
	if Module:IsA("ModuleScript") then
		Sets[Module.Name] = require(Module)
	end
end

-- The RemoteFunction is called from localscript (input key)
-- Start here and after Replicator with InvokeClient

Server.OnServerInvoke = function(Client, Skill, Action, Data)
	
	local list = game:GetService("Players"):GetPlayers()
	for i, player in ipairs(list) do
		if player == Client then
			table.remove(list, i)
			break
		end
	end
	Data.Character = Client.Character
	
	Server:InvokeClient(Client, Skill, Action, Data)
	
	for _, Player in pairs(list) do
		local char = Player.Character or Player.CharacterAdded:Wait()
		local clientchar = Client.Character or Client.CharacterAdded:Wait()
		
		local croot = clientchar:FindFirstChild("HumanoidRootPart")
		local root = char:FindFirstChild("HumanoidRootPart")
		if croot and root and (Player.Character.HumanoidRootPart.Position - Client.Character.HumanoidRootPart.Position).Magnitude < MAXDIST then
			Server:InvokeClient(Player, Skill, Action, Data) 
                     --Send effects for another players
		end
	end

	Sets[Skill.."Server"][Action](Client, Data)
end

This way, when there are other players around, it ends up generating a longer delay than with just one player (that’s what I feel), I believe that with more players there should be a longer delay, I can’t say because I only have 2 devices to test and no friends.

1 Like

RemoteEvents

Pelo que sei, não haveria uma diferença de desempenho entre os dois. Mas, no seu caso, não haveria necessidade de usar uma RemoteFunction, pois você não está returnando nenhum valor.

There may be no reason to use RemoteFunction because it doesn’t return a value, but would switching to RemoteEvent change anything?

Can you give an explanation of why?

One can communicate back and forth through server and client which is remote event remote function can only communicate from client to server that’s all their is to know why are other thinking so hard use which one you need in your case they are both different

RemoteEvent

Client <—> server

Remote function

Client —> server

With my code, I can get RemoteFunction to send all the clients and only the data needed by the server

Using RemoteFunction with my system:

Client —> Server
Close players <—

Other players from afar, on the other hand, suffer no lag due to effects they can’t even see

With everything you say, then the best option would be RemoteEvent, right?
The capabilities are with RemoteFunction, I’m going to do it with RemoteEvent and test it (until a contrary and better opinion)

Thank you for your opinion

This is false. RemoteFunctions can communicate from Server → Client and Client → Server. It is just bad practice to use Server → Client because you can’t guarantee the client will ever return anything and the thread may yield forever.

I think thats my only fear about using RemoteFunction, in case the client leaves the server, but so far there have been no bugs and I’ve tried to cause them

You don’t need to use brain resources worrying about which remote to use.

Use RemoteEvents 99% of the time. If you want you can use them 100% of the time.

The only reason to use a RemoteFunction is if you have a local script that wants to request something from the server. In that case you can either use a RemoteFunction or two way RemoteEvents, it doesn’t really matter it is up to you.

In all other cases use RemoteEvents.

That’s why in my first post I answered the question:

1 Like

Right, so I’ll use RemoteEvent for 100% of the cases, because even RemoteEvent can return a response.

Thank you.

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