How can i use datastores to figure out which cars the player owns?

The question is quite self explanatory… How can I make a system whereas it checks if the player owns certain cars. This is to make up a list of owned cars that can be accessed at anytime as it’s saved on a datastore. IDK how i can make this possible, so i would love to know how.

Should i be using a table and save it… or should i be making it another seperate datastore to serve as a list for each player.

datastores are kind of a tricky topic but what I usually do is save a table of data for each player, ie

Player_1_Key = {
   OwnedCars = {
      "Chevy Camaro";
      "Dodge Charger";
   }
}

Player_2_Key = {
   OwnedCars = {
      "Lamborghini Egoista";
      "Honda Odyssy";
   }
}

In your case I would suggest an OwnedCars table instead of a seperate datastore key for each car

What not to do

Player_1_Key = {
   Owns_Chevy_Camaro = true;
   Owns_Dodge_Charger = true;
   Owns_Lamborgnini_Egoista = false;
   Owns_Honda_Odyssy = false;
}

Player_2_Key = {
  Owns_Chevy_Camaro = false;
   Owns_Dodge_Charger = false;
   Owns_Lamborgnini_Egoista = true;
   Owns_Honda_Odyssy = true;
}

With that now in the car shop whenever you create a car’s gui frame just check if the car is in OwnedCars, if it is then ok its owned, if its not then put it up for sale

EDIT: Instead of using string values you could use more tables that could have configuration settings for car customizability

Im thinking of making it a folder of string values (String value being the name of the cars) then when the player leaves (Since this is a 1-player main menu place) it will saves all the string into a datastore table. The game will check if the player has the name of the cars within the owned player list and then the car will load into to the game.

that is a good idea but it would be much easier to just put all car clones in a folder and then generate based on that folder (also you don’t really need to make it a folder you can change the datastores directly)

true true, but i prefer folders because its kinda easier to change for me.

This is almost the best approach to this task.

What I’d do is have a folder of vehicles (placed in server storage) and a folder of “BoolValue” instances placed inside the player instance. With the name of each “BoolValue” instance corresponding to a vehicle’s name, a value of true indicating that the vehicle is owned by the particular player and similarly a value of false indicating that the vehicle is not owned by the particular player. Then all you’d need to do is save/load the values of these BoolValue instances each time the player leaves/joins respectively.