Adding a Time Out to a Remote Function

Hello!

Im trying to make use of Remote functions, specifically Server to Client to Server, and I’m wanting to make it so that if it doesn’t get the callback within a set time frame it sends a different value

I’ve tried some hackier solutions like

local function pingClient()
      local data
      task.spawn(function()
           data = remoteFunction:Invoke()
     end)
     task.wait(.3)
     if not data then
          return defaultData
     end
end

But it didn’t work in the script. Anyone have a possible solution?

It’s highly recommended NOT to use Remote Functions Server → Client → Server as it can cause a lot of issues on the Server Side (Game Lag for everyone currently in the game, etc).

For this type of setup, I think you would be better using Remote Events and checking that the response from the client isn’t more than the given time. Using this method allows for less possible issues of Remote Functions and will not create lag on the server (The method is more or less asynchronous).

Hope this helps!

1 Like

You should use Remove Event for this and make the client FireServer the time at which they got the remote call

as @SplitYourGamming10 said invoking client can leave it hanging forever if the client leaves