Good ban system / player data manipulation

Hello ! (hoping this is the right category for this topic)

I’m currently creating a game, and I was about to start developping the datastore part, including a banning system, and some in game command but I didn’t khow how to achieve my ideas. I tried to search for some stuff online, but didn’t find anything that’d convinced me.

I’d like to get some feedback on this design I came up, all advices / thoughts are accepted :slight_smile: .

After thinking about it a lot, and trying different ideas, I came to the conclusion of using 2 datastore for a player :

  • A classic datastore where his inventory, gold, etc is stored
  • An ordered data store, acting like a log system for the player

Why not just use 1 datastore with the logs inside ?

Well, I wanted my commands (like /givemoney “PlayerName” “Amount”) to change the data of the player if they were in the same server but also if they were offline or in a different one.

If i was using only one datastore, there could be some problems, for example :

  • I decide to give a player some money with /givemoney. If the player is playing in the same server as I’m then great, no problem he gets his money. BUT if he is playing on another server, I’d need to get his data, then edit it, and finaly push it. And that player will never see this change because when he’ll go offline, his actual data in his server (not edited with the command) will be pushed and will overwrite the changes I made.

  • What if you have some admins in your game which have access to some commands ? If you and the admin do the command at the same time, the player will probably only see one of the two command but not both !

  • Also requiring the entire data of the player (which could be huge) just to add some money seems a bit overkill.

How would you make it work with this ordered data store then ?

So when you want to give a player money, if he is online and on the same server then it’s easy, you don’t even need this ordered data store, just add the money directly to his data. But if it’s not the case, you write a new log.

This log will just write a new key value in his ordered data store, you don’t even need to get his data. The key value should look something like this :

  • key = 45761322-1-9500
    (max 50 character)
    45761322 = UserId of the player who typed the command
    1 = The ID of the action to take, here give the money
    9500 = the amount to add or anything else you want related to the action

  • value = os.time()
    I saw somewhere that os.time() could be not sync across servers, if this is true, you could use berezaa’s method and just add + 1 to the last value when writting a new one

And then you are done, you just need to wait for the player to log in ! When he gets his tabledata from the classic datastore, there needs to be a value (called LastLogSeen) in this table telling the last log value that was seen.
Then you get the ordered datastore with getsortedasync, read each log in order until you get to the last log that was seen by the player and perform all the actions !
And finaly you update the LastLogSeen to the last value of the log written in the datastore

Okay I think I get it but what would be the benefits of using this ?

  • You just need to write a key value in an ordered data store to change the data, and you will never need to get the data table of the player

  • This also act as logs for the player, you can see if you want every command used on a player and who did it

  • Not getting the data table of the player will limit the possibility of the command being overwritten if he was playing at the moment, or if 2 admins write a command at the same time

I think that’s everything so far, if there is something you didn’t understand or if you want even more details, feel free to ask :slight_smile:

Thx for reading

If a free module existed for this, would you use it ?
  • Yes
  • No

0 voters

3 Likes