Hey, I am working on a mining game and I have a bunch of repetitive code, would there be a way for me to have a function that takes a string input and sets the variables below based on the string?
For example, if I wanted to add a new data store named Diamonds, I could just run a function to create the diamondStore datastore
I am using DataStore2
-- Repetitive Code
local coalStore = DataStore2("coal", player)
local coal = Instance.new("IntValue")
coal.Name = "Coal"
coal.Value = coalStore:Get(0)
coal.Parent = leaderstats
coalStore:OnUpdate(function(newCoal)
coal.Value = newCoal
end)
local copperStore = DataStore2("copper", player)
local copper = Instance.new("IntValue")
copper.Name = "Copper"
copper.Value = copperStore:Get(0)
copper.Parent = leaderstats
copperStore:OnUpdate(function(newCopper)
copper.Value = newCopper
end)