Is FireAllClients() the same with a for-loop?

I’m just being curious about are the two codes below have the same network usage?

local event = Instance.new('RemoteEvent')
event.Parent = game.ReplicatedStorage

event:FireAllClients('someData')

and

local event = Instance.new('RemoteEvent')
event.Parent = game.ReplicatedStorage

for _, player in Players:GetPlayers() do
    event:FireClient(player, 'someData')
end

I know they performs the same but how to test their network usage?

In addition, I have a question regarding playing animations for specific players. Should I play the animation on the server or broadcast an event to all clients? Which method is more efficient?

local animation = Replicated.animation
local animator:Animator = Players:GetPlayers()[1].Character.Humanoid.Animator
animator:LoadAnimation(animation):Play()

vs

----- [[server]] -------
local event = Instance.new('RemoteEvent')
event.Parent = Replicated

local animation =  Replicated.animation
event:FireAllClients(Players:GetPlayers()[1], animation)


------[[client]] ------
local event = Replicated.RemoteEvent
event.OnClientEvent:Connect(function(who, animation)
    local animator = who.Character.Humanoid.Animator
    animator:LoadAnimation(animation):Play()
end)
5 Likes

idk, but i think FireAllClients() and loading the animation in server is more efficient because it’s fast and short and simpler and server is more reliable than client

1 Like

Maybe loading it on the server yes, but playing the animation should be done on the client

1 Like

First of all, any performance difference between these is negligible. It’s best to use the simpler solution, which in this case is the first of each.

Considering the documentation says “Fires the OnClientEvent event for each client connected to the same RemoteEvent”, I assume there is no difference between a FireClient loop and FireAllClients, except that FireAllClients may be implemented slightly more efficiently behind the scenes.

You are much better off focussing on what data you are sending rather than how you send the data, because that will have far more impact. The best way to test their network usage is to use them in production and see if they’re too slow for use.

2 Likes

but why, wont it delay too because of FireAllClients()?

The difference is not noticable as @lovableschoolgirl said

Thank you for your detailed reply. I still have a question regarding the server’s task pressure. It is often preferred to minimize the server’s workload to avoid causing lag for all clients. That’s why, when creating particles or other effects, we typically fire them to all clients and have them create the particles locally. However, when it comes to animations, any changes(stop, adjust speed…) to animations require sending remote events. This leaves me wondering whether it’s better to play animations on the server or send them to all clients.
And thanks for reminding me that we should test it in production, but how to “see” a result about whether they’re too slow for use instead of just “feeling” it?

Yeah, I agree that FireAllClients() is better, but if too many animations are playing on the server - considering the server already has many tasks to do - it may cause lag.

FireAllClients is faster because it is handled in C++.

Oh, thanks, but where can i learn that?

I remember seeing a post about how FireAllClients causes a memory leak, and that using a for loop with a task.wait() temporarily fixes it. I’d look into this

1 Like

I mean that all of the Roblox standard functions will always be faster than Lua implementations because it is written in C++ (internally).

1 Like

you know that playing animations on the player’s character in the client-side will also replicate to the server and all clients, right?

It wont make a difference for performance, the only reason to use it is because it looks better.

Considering a for loop under 100 elements takes less than 0.1ms, the 200ms average ping of users will have no effect.

it will simple fire all clients two times, it’s maybe different when someone will leave in perfect second, but if you wan’t to make fireAllClients, then fire it once and then do loop on client

This isnt what OP is asking.

OP is asking if FireAllClients() is a for loop. The response is yes. Its the same. Youll never notice any speed difference.

1 Like

ohhhh, soo sorry, i think he mean for loop inside fireallclients or something like that

As far as I know, it won’t, I have tested it before


well…

1 Like

Yeah, you are right. I suddenly remembered that what I tested is not a player, but a R15 created in the workspace. Thank you for correcting me.