Use of remote events

I need to use remote events to send a number each frame.

example:

in a localscript:

game:GetService(“RunService”).RenderStepped:Connect(function()
game.ReplicatedStorage.RemoteEvent:FireServer(RANDOM_NUMBER)
end)

Does this greatly affect latency?

2 Likes

Why do you need to send a number to the server every frame?

1 Like

It shouldn’t, if this is running each time the game renders a player stepping (walking), the only occasion I could see this affecting latency hugely (and negatively) is if it runs too quickly too much (like a while true do statement with no wait in it, personally I add a wait to basically everything (where the waits should be) to correct issues like that. I suggest adding a wait() at the beginning when the function runs. No number in the wait means it will only wait the smallest amount of time possible (anywhere on a client from 1/10th of a second to 1/10000th of a second)

game:GetService("RunService").RenderStepped:Connect(function()
    wait()
    game.ReplicatedStorage.RemoteEvent:FireServer(RANDOM_NUMBER)
end)

That’s not going to change anything. RenderStepped will fire every frame, regardless of whether you stuck a wait() at the end of the last frame or not.

1 Like

I see the fault in there, so wouldn’t the wait() at the beginning of the function be more helpful, waiting the smallest amount of time possible before firing the remoteEvent on every step, also thanks for the feedback on my reply!

because I need to replicate a single rotation in a Motor6D.Transform

That wouldn’t help either, it would just wait the first time it fires and then it would always fire after the same amount of time. You don’t need a wait at all, a RenderStepped connection will always just fire once every frame.

1 Like

What you should do is something every here and there. 15 times per second is more than enough and is actually the tick rate roblox uses to replicate movement by default.

Something like this should work better

Send the signal from the client to the server at a slower rate. Then you have two options.

  1. Perform translations on the server using Heartbeat (Which could still cause network lag)
  2. Tell every other client about the change, and have them perform local translations.

With some good networking skills, you can make #2 incredibly efficient. Something like this on the server

local network = {}
network.RemoteEvent	= game.ReplicatedStorage:WaitForChild("RemoteEvent")

function network:FireClient(client,data)
	network.RemoteEvent:FireClient(client,data)
end

function network:FireAllClientsWithException(clientToIgnore,data)
    for iteration, player in ipairs(game.Players:GetPlayers()) do
    	if player ~= clientToIgnore then
    		network:FireClient(player, data)
    	end
    end
end
5 Likes

This actually does change quite a bit. RenderStepped is known to fire functions before a frame renders. Putting a wait or an expensive function there can delay when a frame renders and block other code.

1 Like