How to save client data?

I’m very unfamiliar with datastores, but let’s say I had a keybinds module with a list of keybinds on the client, how should I make it so that data saves when the player leaves the game? Should the server invoke a remote function to the client?

Well, you can’t save data from a local script, so I would fire it to the server with a remote event to save their data.

1 Like

Well I heard it’s bad practice for the client to tell the server when to save data. Could I fire an event to the client instead (or use some kind of remoteFunction) that retrieves the client’s data from the server?

When the client saves/updates their keybinds you should send the list of keybinds to the server for saving. Ofc this would be through a remote event btw

1 Like

Should I tell the server to update keybinds data every time they update an individual keybind? If so, it would make this system a lot easier!

You could send the key binds to the server for saving when they leave the game

2 Likes

Well, anytime you want to save a player’s data, it has to be written in a server script.

The best method, (I think) would be to attach a playerremoving event in a local script which fires a remote event to the server to save their data.

Also, you don’t need to worry about exploiting with keybinds in the datastore too much. All it will do is change the keybinds in a round-about way or bug out their game.

Exploit safe datastores are more important when dealing with things like inventory’s where the player could give themselves items of value without earning them.

1 Like

Okay, thank you so much for your help, I will just use a remote event on the client that fires to the server

1 Like

Yeah I think you should do that too.

Also make sure to implement a bindtoclose for the last player in the server.

1 Like

Also, how would a playerremoving event in a local script work? Could you elaborate more on that?

Instead of this, why not just fire the remote event once the keybind is set by the client?

So on the client it would look like

  • Set keybind
  • Immediately FireServer() with change

On server
when OnServerEvent is fired, update their data stored on the server side

Then when the player leaves on the server, simply update their data as a whole then

1 Like

If you spamed doing this the data store request will fill up and players keybind data wouldn’t save their keybind so @obamagremlin i would sugest going with @The_DuckDeveloper idea