How can I reduce client lag when firing a remote event multiple times?
I have developed a BETA version of a game, think of papers please, it's a loop of a random frame showing, detecting to keypresses, sending it off to the server, and moving a part, that loop repeats with a while true do
loop.
Whenever the frame shows, the user can either press [F] or [G], and dependant on the information, it's either right or wrong. The problem is that I need to wait for the user to make the input so I used a remote event to tell the server when that input occurred, but it causes more lag each time it is fired, by around 3 loops in a lag spike is noticeable.
I thought of making the part movement client-side (because it is a single-player game) but I have no idea how to do that, and if it ever becomes a multiple-player game, that would not really be practical.
How can I repeat the loop indefinitely without lag spikes occurring?
This is the loop:
This is the relevant function:
2 | rs.OptionPicked.OnServerEvent:Connect( function () |
4 | rs.OptionPicked:FireClient(player) |
And this is the keypress detection:
01 | user_input.InputBegan:Connect( function (key_input) |
02 | if key_input.KeyCode = = Enum.KeyCode.F and picked = = false and script.Parent.Visible = = true then |
05 | game.ReplicatedStorage.OptionPicked:FireServer( true ) |
07 | elseif key_input.KeyCode = = Enum.KeyCode.G and picked = = false and script.Parent.Visible = = true then |
10 | game.ReplicatedStorage.OptionPicked:FireServer( true ) |