So I have a shop system where people can buy swords. I want the purchase to save and be loaded when they rejoin so instead of prompting them to puchase again it can just say equip, and for this I had a bool value in each sword (like below)
I have a module script I changed from my normal playerData script to solely save the sword info so I can put it in a seperate DataStore (though that might be useless)
I imagine it’s because the player’s character left so it can’t find the playergui but that complicates things since I don’t want to have to autosave every 10 seconds.
I recommend you create a list/table or a folder serverside that is created when the player has joined then add all the boolvalues/etc. you want to it and change it to according to if they purchased or not, and when the player leaves before you :Destroy() the folder, save the data in the folder/table/list.
For reference: Players.PlayerRemoving | Documentation - Roblox Creator Hub
So I’ve made the folder in ReplicatedStorage and when a player joins it creates another folder in that folder under that player’s name.
And I’ve also changed the module so that it just saves any value inside the player’s folder as true or false.
Now I just need to create each bool value for each sword I have, but what method should I use for that. I was thinking of using for in pairs in the startergui to see how many swords there are and just make that many bool values but I was wondering if there’s a better way.
Thats one way to create the boolvalues, I’m not entirely sure there is a better way unless you manual change the number of sword bools the system produces each time you create a new sword (but this would be time consuming). In the end I would use a “for loop in pairs” for this, however you can also consider that boolvalues aren’t the only way to save data, you could have a script store a list that data is stored in, and if the client needs to read the data, you could probably send it with remoteEvents, however the client won’t be able to directly access the data as it needs to go through the server and wait for it to give it readable data.
Now, using a folder with bool values is not a bad idea to save your data, but there is no point for the client to have access to the readable bool values. In order to understand this, we must venture towards client manipulation. Where, exploiters and hackers can change the bool values to say something else, and if you have a local script it will show the change, HOWEVER the server will not accept these client changes (if FilteredEnabled is on, basically prevents hackers from accessing server data and taking ownership), so if you want the client to read the data to check if the player has PURCHASED the sword, it is not optimal, I would just run the script through the server and make it check if the player has access to the sword, I WOULD NOT advice you take this action through a local script.
An in pairs loop should work fine, I’m unsure if there’s any other way besides saving it all inside a script instead.
A good idea would be to save only owned swords and then apply all the values to all the sword bools, so if you add new swords it wont error when you expect a certain table length