Keeping it simple and clear. How can I save String Value Objects in an specified DataStore2 DataStore and get the descendants of an specificed DataStore2 DataStore as well?
Also I’m asking specifically about String Value Objects not strings.
Keeping it simple and clear. How can I save String Value Objects in an specified DataStore2 DataStore and get the descendants of an specificed DataStore2 DataStore as well?
Also I’m asking specifically about String Value Objects not strings.
Can you explain why you want to save a string value object instead of a string?
Now that question aside, what you can do is make an array holding the properties of the string value object, once you have that array, you can encode the array into a string using JSONEncode to use less data on the datastore.
Example code:
-- Save data
local stringValPropertyArray = {
name = "name", value = "string", class = "StringValue"
}
local itemString : string = HttpService:JSONEncode(stringValPropertyArray)
dataStore:SetAsync(dataKey..Player.UserId, itemString)
-- Getting data back
local stringValObjString : string = DataStore:GetAsync(""..Player.UserId)
local stringvalArray= HttpService:JSONEncode(stringValObjString)
I’m sure you got the other steps, but I’ll explain to you anyways.
If you’re going to save a ton of string value objects into a datastore then you should again use an array to store those arrays that contain the object data then encode them to save bits.
Arrays are basically tables if you didn’t know, please let me know if you have any questions about this.
I am making an Tower Defense Game. I am of course gonna use alot of string values. The reason why is they can act like an key and than equip the player’s towers using FindFirstChild on a list of the bits of the data names in the array and equip the towers in the universal place. However I am organizing it in a folder and I do not know how to get the names of the bits of data stored in the array to equip the towers in the universal place instead of using an folder. How would I achieve this?
An example: I bought an tower I got an string value in the folder and it saves the name of the tower, (Name Example: Minigunner) into the array as bits of the data as an example. And how would I get the bits of data names in the array in the universal place as I need this for players towers to automatically equip like in Tower Defense Simulator.
And than the bought tower string value will be destroyed in the lobby when the bit of data is stored into the array in the lobby to save on resources.
As I just need the bits of the data names in the array in the universal place.
Sorry if I made it sound confusing.
I have solved this topic myself. IF anyone out there and is making an tower defense game but don’t know how to save the towers.
You can make an DataStore and than set it as a array (an table basically) with the DataStore2 Module.
When somebody buys a tower you can put an StringValue in an folder in the player called “BoughtTowers” and you wanna insert the StringValue into the array and destroy the leftover StringValue to save resources of course.
Now you can loop through the array in an universal place and use any method of equipping towers! I personally will use an FindFirstChild Name method to find if any of the array’s mame’s is related to an tower.
Or you can of course use Tidyen’s method as I inspired my method off of his/hers since it gave me an idea.
Thank you, Tidyen for helping.
Warning: IF you’re gonna use my method do keep in mind that this can be easily exploited. Please find an method of preventing it! As I found my own method of preventing this however a client won’t be able to access the player’s data folder from this. But that is perfectly fine since you aren’t suppose to get the player’s bought tower folder data from the client! As you can use RemoteEvents instead to get the player’s bought tower folder data | Server - Client | Client - Server Communication | PLEASE Secure You’re Remote Events if you need to get the player’s data from the server and than pass it onto the client as this can end in a REALLY bad scenario If you don’t secure it. As exploiters can do anything they want with you’re RemoteEvents and do some really damaging stuff. I highly recommend doing Sanity Checks if you wanna secure you’re Remote Events for the player’s data or anything related.
Sorry if I wasted you’re time with this topic!