DataStore for entire game

Hello,

im currently trying to do a RP Game where you can buy houses and all.
Now my goal is that if you by a house, you own it and if you rejoin the game, even on a different server, you can still just enter that house.

My problem is that I haven’t found any way yet to save data for the entire game.

So basically like this:

Player: Buys House → Server: Reserve house N°1 for Pyr → Game: House 1 belongs to Pyr

Player: Tries to open door → Server: Does 1 = Pyr? → Game: Yes → Server: Open door.

Is there any API similar to DataStore to do this? Thank you very much!

You’ll probably want the datastore to save the userID of the player and have a script in the door of the house check if the player trying to enter is the same userID saved on the datastore.

You can do this with Datastore by setting a global key (the key isn’t the player’s userId, but simply “Server” or “Global” will be enough.) This way for every server created, it loads the global store and loads owned houses. And when players attempt to open the door it references their ID with the door’s owner ID.

Example:
local doorOwners = { door1 = userId1, door2 = userId2, etc… }
then save/load doorOwners table to a datastore under key ‘server’.

Note: when adding owned doors, always retrieve the latest save and then check if the door exists, because in another server it could be taken already.

1 Like