How can i create a shared datastore?

i have a system where players can create save slots, kinda like minecraft you can say
but the problem is with co-op, it gets all messy cause different data saves to different people. It would be nice if i could have one datastore(im using profile service btw) instead of “slot_1” being assigned to each of the players, make it to where they just share a single “slot_1”

I already have the save slot system in place

I’m new to profile service and data stores in general. So i’m not sure if there’s actually a way to do this, if you know a way please share :+1:

1 Like

I’m pretty sure, with the successor of ProfileService (ProfileStore), it’s not possible, as it is focused on player data, that isn’t shared or stuff like that

However, it very much is possible with the usual DatastoreService

I am not familiar with either datastore module, as I’ve only used DatastoreService, without any datastore module, so my answer will be based on that

With normal datastores (ie no Datastore library), you can save slots to an arbitrary key (it could literally be a GUID, and then, you save the key (the GUID) inside of each player’s data (this could be in the ProfileService data table). So when a player is loading, you can retrieve the key to their slot, and then do another datastore request to load the slot itself. To allow multiple players to use the same slot, you can provide the key to every player

This does bring a problem though, what happens when the two players want to load the same slot, on two different servers? I assume you don’t want both players to load the slot, so I’d assume you’d want a lock system, so only 1 player can load the slot at a time. That is possible using UpdateAsync, as update async garantees request to a key are done in order (but the order is not guaranteed), and not at the same time, so the first player to load the slot can change a variable in the slot table to lock it, and the second player, when he tries to load it, fails, because he sees that the slot is locked.
There is more logic required for handling cases where datastore requests fail when unlocking the slot, by using a timeout system. I can explain that in more detail if relevant

So this answer is more specific to datastore in general, I will let others talk about ProfileService

2 Likes

using some stuff you said got me closer, but the problem with profile service is it locks profiles to be only used by 1 player, but i need them to be able to all use it. So at the moment that’s what im trying to figure out

2 Likes

I can’t help you regarding ProfileService,

If I had to suggest something, either maybe profile service has some feature to handle that, or you’d have to learn to use DatastoreService, for the slots. You can still use ProfileService for the player data, by saving the datastore key of the slots, to the player’s profile

Learning to use DatastoreService can be useful either way, as it being more lower level, allows for much wider possibilities. I have this topic for fairly unique datastore framework, it is probably way too technical for you (especially the framework itself), but Section 1 could be an interesting read? I don’t know lol

There are many tutorials on the forum, or on youtube, such as:

Although I am not always satisfied with the way tutorials explain the benefits of UpdateAsync() over SetAsync(). I may have read the two tutorials I linked above, but if I did, that was too long ago for me to remember how good they are

1 Like

i never really thought about actually learning datastores, ill look into it thanks!

1 Like

Ain’t trying to ruin the party or nothing and I hope I’m not giving false info but It is fairly simple, what you’ll have to do is load the player data normally as you would by their userid and then inside their data add a “saves” table with the keys inside being data keys that were generated using the httpsevice unique id function, note that the you generate the keys only one time once the save profile was created, and then through that data tables you load the saves into a ui and let the player choose a save profile that can be someone elses too,
but the issue is that profileservice wont allow that, for 2 players to load the same profile therefore you need to make sure only 1 player loads that profile each time so do some type of check to see if that profile is already loaded or not and to save both players that through one profile you need to implement your own system for it, the main struggle would be if the player that holds currently the profile leaves what happens next, well in that situation you need a function that keeps track of that and lets the other player that stayed hold the profile,

much better solution would be not even assiging the profile to any player but an object which is the world that is loaded (since you said its some type of minecraft game), and when the server is closing then save the profile,

hope this helped

1 Like

It’s kinda working using the last method you said, ill play around with it more to get it perfect. But that was pretty much all i wanted so thanks!