Title pretty much explains it all. How would i save and load multiple values within a player gui, via DataStore. I do not know much about the DataStore, but i do know its used for saving and loading stuff
Heres a screenshot of what im trying to save and load: (if the “Owned” values within the folders are equal to true)
i didn’t say that this was a client only thing. If anything this is a server thing. this is because i only change these values with only server side scripts.
You should probably put the values inside the players so you only need to load them once, then change the data in the values accordingly using DataStores, when player leaves or game shutdowns you just save the values val…
To explain the concept :
Player joins you get the players stats ( from the datastore ) and create the player its own values
Change the values to the players stats and place them inside the player ( whatever.Parent = Player )
Whenever you’re updating data and the player is in game just change the values value
When the player leaves save the values value inside the datastore ( and maybe having a timer every x amount of time is good )
I suggest putting all of those stuff inside 1 folder called “Data” and then placing it inside the player.
Also I just reread what you said, I am sorry that I kinda answered a completely different question.
To use DataStores and load different values and load them I suggest saving a table :
I do not recommend this because people can easily hack the values and theoretically become too overpowered. Because you cannot control what a player does to it’s own client
Yes, putting the values in the players is important but there’s an issue for some game designs. If you want to check for buying or otherwise, you can’t use the client’s stats so you have to request from the datastore you just updated. This can lead to datastore queues if you don’t handle it properly. Suffice to say, it is much safer to just store the stats on ServerStorage - it causes no harm whatsoever, is much more organized, and is faster in the retrieval process as well.
But like you said, using a table is a good way to save/load data.
For OP, if you want to assign the data from the table to your server stats, look for the table’s keyname (ex. “Weapons”) if you have a weapons folder, then create a value (idk if you use number IDs or strings) in your Weapons Folder in the server for the player you are loading the data, for all the weapons they have in the table.
You do this for all the stats/inventory. So obviously, you need to organize your table the same way you organize your ServerStorage inventories. Ideally,
UserId Item/Class/Stat Name Items/Stats the player owns.
If you read my post you would see that I have said how you’d update the values and it doesn’t contain getting data from the datastore,
Saving the values in ServerStorage and inside the players would be the same thing except when the player leaves you don’t have to delete the values from the player while if you put it on ServerStorage you need to delete it yourself.
I said to put it in the player because OP wants to use them for PlayerGuis I think that the values would be perfect if he were to check whenever the value is changed and change the values from the server because they’ll obviously replicate, putting them inside ServerStorage will make it so OP has to ask the server for the stats everytime he needs to update something or check if something changed… ( well he could do RemoteEvents and check for OnClientEvent but yeah… )
Ah I guess you misunderstood me,I am bad at explaining sometimes here let me reword my posts :
When the client changes something that’s under the Player Object it Will not replicate to the server,
so there is no reason for you to be scared if it has been tampered with by the client ( After all you’re going to handle the purchases on the server ).
Whenever you update someones stats you simply change the value of said stat inside the Player Object and it’ll replicate both to the server and client so getting changes is as simple as checking when the value is changed ( Inside the client you do Value:GetPropertyChangedSignal(“Value”) )
Saving the data can’t be any easier!
Either you have a loop every x amount of time and update the data in the datastore or you could just update it whenever the player leaves. ( game:BindToClose and Players.PlayerRemoving )
I do, i store my tools in server storage, but i have the information about the tool in a gui. I would just like these values to save and load. Its honestly the exact same as having a leaderstats inside the player. Instead its a gui containing the information. I just do not know how to save these values and load them
I believe BasedFX answered your question very well, I recommend you to check out how arrays work.
You need to use the same concept as what he provided:
The difference here is that instead of just having the two weapon names, you’ll need to make more items in the Weapons array for your other weapons (if you have any).
Note: Make sure you cache/store the data in the .PlayerRemoved event when the player leaves as soon as possible.
Just a question. Is this not the same as having a folder containing these same values? why do i have to use a script or a Module all of a sudden? couldn’t i do something like
In some sense it is the same but it just makes it tedious to code. It’s good practice to store data in a table rather than using folders and values. In some cases it may be better to do otherwise but you should only really use arrays to handle and store data.
It is also good practice to store data in modules for giving a modular approach to programming. Modules can be called from different scripts depending on where it’s located. It allows you to keep your programming centralised stopping you from being more liable to make logical errors.
If you’re not much familiar with modules, please check it here