Alternative way to make a Datastore Leaderboard

The datastore script i use is something along these lines:

local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("DatastoreKey")

	local Leaderstats ="Folder", Player)
	Leaderstats.Name = "leaderstats"
	local CashV ="IntValue", Leaderstats)
	CashV.Name = "Coins"
	CashV.Value = 0

	local Data = DataStore:GetAsync(Player.UserId)
	if Data then
		CashV.Value = Data.Coins

	DataStore:SetAsync(Player.UserId, {
		["Coins"] = Player.leaderstats.Coins.Value;

And everytime i want to add a new value to the leaderboard, i have to add it 3 times:

  • With the part (local newValue ="IntValue", Leaderstats))
  • On the data loading part (newValue.Value = Data.Value2)
  • When the player leaves (["Value2"] = Player.leaderstats.Value2.Value;)

I wanted an easier way to make this, as working with a lot of values can be repetitive and takes a crappy amount of time, it would already help if there was a way to automize this script so i only need to add the new instance once or twice, or even a new type of datastore script.


If you wanted a new DataStore method, there are some community resources that make it much easier to do it. EX:
My resource