I need some help with finding out how to do stuff with data store.
So let’s say that a user wants to look at something another player writed, but that user isn’t in the game anymore.
Something kinda like one of those games where players write notes and they stay in the game forever.
Data Stores should be created or referenced using game:GetService(“DataStoreService”):GetDataStore(“dataStoreName”)
dataStoreName is basically string or number that identifies certain DataStore f.e. dataStoreName can be “UserData”.
:GatDataStore() function itself returns GlobalDataStore instance so it should be called as local or global variable.
(f.e. local userDataStore = game:GetService(“DataStoreService”):GetDataStore(“UserData”)
Saving is done with :SetAsync() function of GlobalDataStore and its syntax is :SetAsync(key: string or number, data: string or number or array) where key is basically a entry in GlobalDataStore. It is safest to use Player.UserId as the key.
Max rate of saving that would not make the script yield is once every 5 seconds.
Loading is done with :GetAsync() funtion of GlobalDataStore and its syntax is :GetAsync(key: string or value) and it returns data saved to certain entry, therefore it has to be called while defining variable.
For safety, all operations related to DataStoreService should be put inside pcall() function, as it may just fail from time to time.
Well what im thinking whend the client send the player thats looking for then the serverstorage does a GetAsync(otherplayer.UserId) or something like that
Well then there’s function :GetPlayerFromUsername() or something somrwhat similar.
It returns Player instance no matter if the player is in game or not.
Then You can load data saved under that player’s UserId