Slow Client Fix

Hi all. I have a server script that sends strings to clients and the client would display it out for the user in a typewriter thing. If the client has a bad connection or is performing slowly, it would receive the string too late and two requests would essentially overlap each other. I tried to add a time compensation but that would just make the client out of sync compared to everyone else. I don’t want to store the strings client-sided, so I’m not really sure how to fix the overlapping properly. Note: I am not yielding when doing the typewriter part, but I am yielding in between sending strings to clients.

Suggest doing a code similar to this:

local res

delay(1, function() -- Don't worry, this doesn't pause the other lines, it skips this while waiting 1 second. Similar to spawn function.

  if res == nil then
     print("It didn't send the request. Maybe took so long?")
  end
end)

res = instance.RemoteFunction:InvokeClient(client, ...)

Refer to the following function via link:
https://developer.roblox.com/en-us/api-reference/lua-docs/Roblox-Globals

You should, unless absolutely necessary and no other alternative suffices, avoid invoking the client. Refer to the warning in Server to Client under Using Remote Functions in the following article:

https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events

1 Like

Right. Another way, use RemoteEvent. This way, it can communicate without interruption.

On the server code, you should have a code similar to this:

local lastsentRequests = {
  [1] = 32, -- Client's userid is 1 (Roblox's UserId), just pretend. 32 is the last time client had a last request.
}

function eventCalled(client, ...)
  if lastsentRequests[client.UserId] ~= nil then
    lastsentRequests[client.UserId] = time()
  end
end

Instance.RemoteEvent.OnServerEvent:Connect(eventCalled)

local onTime = time()

instance.RemoteEvent:FireClient(client, ...)

delay(1, function()
  local timedif = onTime-lastsentRequests[client.UserId]

  if timedif > 10 then
     print("It took long to respond.")
  end
end)

My main issue here is that when the client gets a remote event too late, It would over lap two remote events. It usually does not miss the entire remote event, it just gets the remote event late which causes a future remote event to overlap with the past one. I also don’t want to pause the server that sends all the strings for a client to catch up.