Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Is there a way to have a consistent communication delay time with remote events?

Ok so I'm trying to have a server side script create bullet trails, but the local script calls the remote event which creates the trail from the server script. The system works but the only problem I'm having is that the communication delay time isn't consistent. Sometimes the trail will appear instantly but other times the trail will take around 1 second to appear, which can become incredibly annoying. I just want to know if there's any way of keeping this delay time to a minimum or if there's any other method of fixing my problem. Thanks.

Server Code:

local createTrail = script:WaitForChild("createTrail") --createTrail is a remoteEvent
createTrail.OnServerEvent:connect(function(_, Origin, P, gunIgnore, S)
	local Trail = Instance.new("Part")
	Trail.BrickColor = S.trailSettings.Color
	Trail.Transparency = S.trailSettings.Transparency
	Trail.Anchored = true
	Trail.CanCollide = false
	Trail.Size = V3(1, 1, 1)
	local Mesh = Instance.new("CylinderMesh")
	Mesh.Offset = V3(0, -(P - Origin).magnitude / 2, 0)
	Mesh.Scale = V3(S.trailSettings.Thickness, (P - Origin).magnitude, S.trailSettings.Thickness)
	Mesh.Parent = Trail
	Trail.Parent = gunIgnore
	Trail.CFrame = CF(Origin, P) * CFANG(RAD(90), 0, 0)
	delay(S.trailSettings.visibleTime, function()
		if S.trailSettings.disappearTime > 0 then
			local t0 = tick()
			while true do
				local Alpha = math.min((tick() - t0) / S.trailSettings.disappearTime, 1)
				Trail.Transparency = numLerp(S.trailSettings.Transparency, 1, Alpha)
				if Alpha == 1 then break end
				wait()
			end
			Trail:Destroy()
		else
			Trail:Destroy()
		end
	end)
end)

Local Code:

if S.bulletTrail and S.trailSettings.Transparency ~= 1 then
	createTrail:FireServer(Main.CFrame.p, finalP, gunIgnore, S)
end

2 answers

Latency
I shot you first!

Welcome to the world of networking, network logic and lag compensation.

  • When you send a RemoteEvent, it has some prioritisation going on - If there's a lot of replication data, your RemoteEvent is going to be sent last so that the rest of the game appears to be working fine.
  • If the Player has a bad connection to the game (Geographically far away or bad routing) then they'll have a high ping and it will take longer for the request to hit the server and replicate back to the client.
  • If the Player has a bad connection to the game (Low throughput for upload/download) then their connection will be choking and it'll again take longer for the request to hit the server and replicate back as the network tries to fit a camel through the eye of a needle.

So, how do you fix it?
Your player wants instant feedback. Create the tracer/trail locally when they fire, and then sync it back with the server after the replication comes back. This is hiding the lag and it makes things feel thousands of times more responsive. It doesn't make the other players see it any sooner, but there's not really any way to fix that without designing your own replication to minimize network impact.

Above all else, remember that Roblox is designed off of an all-to-all replication of gamestate. There is a lot of data that needs syncing up in that case, and it can get incredibly messy if you don't offload things to the client where 1:1 network precision is not required.

It is normal for my ping to be about 120 ms or more so I usually set my game to a delay of 200 ms. Roblox studio includes a network delay setting which may help you limit this delay.

You can set the incoming lag here click here it can se set in file->settings->network

Here is an article to help limit lag click here

This discussion is preserved as it was. New answers, comments, and votes are closed.