Handling Remote events delay?

so, i wonder how A Bizzare Day optimized their game, so i try my best to make it look lagless, but… there’s 1 thing that make my game looks lagging, yep, its remoteEvents delay, so basically i fired a remoteEvent into the server Once then the server would loop until that remote told the server to stop the loop.(which means i dont spam remoteEvents i only fire it once then a loop happens in the server)
the script is like this :

barrage.OnServerEvent:Connect(function(plr,bool)
	-- Player Properties --
	local character = plr.Character
	local primary = character:FindFirstChild("HumanoidRootPart")
	local stand = plr.Stand.Value
	local hide = stand:FindFirstChild("Hide")
	local frame,owner,damage,defense,speed = GetStandData:Invoke(stand)
	local barrage_delay = 0.1/speed.Value
	local damage = damage.Value/4
	local SFXRemote = game.ReplicatedStorage.SpecialFX.BarrageShockwaveSOFT
	if hide.Value == true then
		hide.Value = false
	end
	-- Barrage Start --
	if string.match(stand.Name,"The World") then
	if bool == true then
		if checkModule:Check(character,true,true,true) == true and not character:FindFirstChild(CD_Name) then
			SFXRemote:FireAllClients(true,character.HumanoidRootPart,BrickColor.new("Institutional white"),barrage_delay)
			local p = Instance.new("BoolValue",character)
			p.Name = "BarrageDur"
			debris:AddItem(p,Barrage_Dur)
			PlayAnim("Barrage",stand,2/speed.Value,Barrage_Dur)
			frame.Value = CFrame.new(0,-0.5,3)
			while character:FindFirstChild("BarrageDur") and character.Humanoid.Health > 0 do
				wait(barrage_delay)
				local check
				if character:IsDescendantOf(workspace.TSImmune) then
					check = true
				else
					check = CTS.Value == false
				end
				if check then
					
					spawn(function()
						local hb = rangeDamage((character.PrimaryPart.CFrame * CFrame.new(0,-1,-2)).p,4.5,damage,character,character.Name.."PPP",0.1)
						for i,v in pairs(hb) do
							if v ~= character then
								spawn(function()
									playSound(light_hit,v.PrimaryPart)
									AddKnockback(v.PrimaryPart,primary.CFrame.LookVector*1,0.8)
								end)
							end
						end
						wait()
						local hb2 = rangeDamage((character.PrimaryPart.CFrame * CFrame.new(0,-1,-2)).p,4.5,damage,character,character.Name.."PPP2",0.1)
						for i,v in pairs(hb2) do
							if v ~= character then
								spawn(function()
									playSound(light_hit,v.PrimaryPart)
									AddKnockback(v.PrimaryPart,primary.CFrame.LookVector*1,0.8)
								end)
							end
						end
					end)
				end
			end
		end
	else
		SFXRemote:FireAllClients(false,character.HumanoidRootPart,BrickColor.new("Institutional white"),barrage_delay)
		makeCD(character,CD_Name,CD1)
		frame.Value = CFrame.new(3,-0.5,-2)
		for i,v in pairs(stand:GetChildren()) do
			if v.Name == "Barrage" then
				v:Destroy()
			end
		end
		for i,v in pairs(character:GetChildren()) do
			if v.Name == "BarrageDur" then
				v:Destroy()
			end
		end
	end
	end
end)

so a delay would happen then it will make the player wait about 1-2 secs before seeing the damage.
how do i make it seem lagless? is there any way to prevent this?
game link(if you want to try it yourself) : eyrtuiop232's Place Number: 37 - Roblox
Controls :
Press E for Barrage
Press R for Strong Punch
Ctrl to run/walk
Q to hide/show stand

1 Like

I saw a game development talk by the lead programmer of Overwatch and they had dealt with a similar problem during development. In a nutshell, their solution was to have the client update what it thinks the damage should be. Then the server eventually tells the client what it actually was. So basically just apply the damage locally then the server will eventually replicate over the actual value (which will almost definitely be the same, but we’re accounting for exploiters here)

Here’s the talk I mentioned. I would really recommend watching it (I’ve watched it 3 times already). It’s extremely interesting and definitely worth the time. They discuss the architecture they used (ECS) and how they deal with high pings, packet loss, etc. They employ some pretty ingenious methods to make the game look smooth at any ping.

12 Likes