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")

game.Players.PlayerAdded:Connect(function(Player)
	local Leaderstats = Instance.new("Folder", Player)
	Leaderstats.Name = "leaderstats"
	local CashV = Instance.new("IntValue", Leaderstats)
	CashV.Name = "Coins"
	CashV.Value = 0

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

game.Players.PlayerRemoving:Connect(function(Player)
	DataStore:SetAsync(Player.UserId, {
		["Coins"] = Player.leaderstats.Coins.Value;
	})
end)

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

  • With the Instance.new part (local newValue = Instance.new("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.

Thanks.

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