i want to save leaderstats but how? im new to scripting and im making a game, (only answer if you know) im using the alvinblox car spawner gui system and i want to know how to save the cars that i bought using that
how do i save leaderstats?
1 answer
Instead of using leaderstats for displaying that a car has been bought one simple way to save that data would be to have a folder, probably in the player, and when a car is purchased, create some kind of value referencing the car, either a string value for the cars name/is or an object value referencing the car if it’s in replicated storage or something. The best way though would be to reference the cars with strings because that’s what we will have to do for the datastores. Assuming we’re using string values these are basically how we would convert the roblox objects in the folder into datastore data:
-- function for loading the players car data
function LoadCarDataFromTable(player,t)
-- get the folder in which the player will have their car data stored
local folder = player:FindFirstChild(“PurchasedCars”)
if not folder then -- create a new folder if this is the first time
local folder = Instance.new(“Folder”)
folder.Name = “PurchasedCars”
folder.Parent = player
end
local data = t.PurchasedCars
for i,CarId in pairs (data) do
-- here we create new string values for each car owners and put them in the folder
local sv = Instance.new(“StringValue”)
sv.Name = CarId
sv.Value = CarId
sv.Parent = folder
end
end
-- function for saving the players car data
function AddCarDataToTable(player,t)
local folder = player:FindFirstChild(“PurchasedCars”)
localCarData = {}
if folder then
for i,v in pairs (folder:GetChildren())do
table.insert(CarData,v)
end
end
t.PurchasedCars = CarData
end
So these two functions have an input of the player and the data table. With the second function though it is saving a new car table into that data table because usually datastorea are used for more than just one piece of data. You would then save that data or when you are getting data you would use it in the function that loads it into the folder. Anyways I’m assuming you know how to use data stores and how to save and retrieve data. If not get started by reading this
Edit: Im on mobile so I’m assuming the indenting issues are just on my end but please tell me if they aren’t.
3 comments
where do i put it? workspace? severscriptservice? severstorage?
ServerScriptService
ok
This discussion is preserved as it was. New answers, comments, and votes are closed.

3 comments
You wouldn’t want to use leaderstats to save what cars you’ve bought.
You need to make a table of purchased cars for each player, then use DataStores to save and load it
thanks kiriot22