How can I securely fetch data from the client when a player leaves the game?

In the game that I’m working on, players can render into areas on the map called Regions. These regions will be used for displaying the region name when the player enters it, regional lighting, etc. on the client for performance reasons. However, I’m currently trying to figure out how to safely and securely design a system that gets that information on the server when the player leaves the game.

For context, the start place for this game features a character selector and a character creator. If the player has a created character, then the character selector will view the player’s last known place in the game as well as their region in that world. However, as this data will be fetched on the server to be saved, I’m currently trying to figure out how I actually fetch that data.

The issue that I’m facing is that I can send a remote event system/remote function to the client asking for the information and storing it in their data. However, I’m worried about this taking too long and effectively causing a gap in the player’s data. I’m already going to sanity check the result by making sure that the region name is valid and is actually a string but if the data takes too long, the mentioned issue might occur. This game is using ProfileService for the data handling.

How can I resolve this issue and if fetching the data when the player leaves is potentially problematic for the listed reason (or any others), what are some strong alternatives, such as asking the client for the information every few seconds or so?

1 Like

I suppose what you can do is have its meta data - the stuff you talked about here

to be on the server, replicating its meta data from a datastore onto the server storage. If the user wants that data it can only get it by requesting it to the server. Another method is, keep the data on the client however create new user data from the newproxy() function and set its meta data to that proxy. From there you can verify it. However in general the solution for stuff like this is to have a server authentication model, where if the player wants to update something it has to send a request to the server, where then the server sends an OK request back to it.

EDIT: If you are worried about it taking too long you can have the clients client cycle (this is like the spinning rainbow wheel on mac by using using game:BindToClose())

The game is a multiple place game and the data being gathered is being shared using ProfileService amongst all of them. The actual regional data will be from a completely different game and only stored on the server, which is why I need to get it from the client and send it to the server when the player leaves that game.

Additionally, I don’t really see why I would need to use newproxy at all as I don’t need to create a new, blank userdata. Futhermore, BindToClose doesn’t help as that’s for when the server shuts down, not when a player leaves it.

Although I’m not sure if it’s an amazing solution, I decided to go with connecting a remote event to listen for the response from the client in the PlayerRemoving event and then disconnect it after a valid response is released or if it’s been too long (such as a few seconds). I think that’ll work fine but as I’m unsure about that solution and since I’m curious if there’s a much better one that I’m not thinking about at this time, I decided to keep this thread open as unmarked for a solution.

2 Likes

For some odd reason, the idea that I can just send a remote to the server to store the region whenever a player enters it completely escaped me. In hindsight, I’m surprised that I didn’t think of that sooner (or honestly at all). Programming is fun sometimes, right? :confused:

Thanks for @B_rcode for pointing out that quite obvious oversight.

1 Like