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)
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
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.
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.
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
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