Hi. I’m trying to make stats, but I’m not sure if this is the most efficient way to do it. Can you help me?
local ds = game:GetService("DataStoreService")
local MoneyStore = ds:GetOrderedDataStore("MoneyStore")
local LevelStore = ds:GetOrderedDataStore("LevelStore")
local ExpStore = ds:GetOrderedDataStore("ExpStore")
local IncomeStore = ds:GetOrderedDataStore("IncomeStore")
local mng1Store = ds:GetOrderedDataStore("mng1Store")
local mng10Store = ds:GetOrderedDataStore("mng10Store")
local mng100Store = ds:GetOrderedDataStore("mng100Store")
local mng1000Store = ds:GetOrderedDataStore("mng1000Store")
local mng10000Store = ds:GetOrderedDataStore("mng10000Store")
local mng100000Store = ds:GetOrderedDataStore("mng100000Store")
game.Players.PlayerAdded:Connect(function(player)
local playerkey = "Player_"..player.UserId
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local money = Instance.new("IntValue", leaderstats)
money.Name = "Money"
money.Value = MoneyStore:GetAsync(playerkey) or 0
MoneyStore:SetAsync(playerkey, money.Value)
local level = Instance.new("IntValue", leaderstats)
level.Name = "Level"
level.Value = LevelStore:GetAsync(playerkey) or 1
LevelStore:SetAsync(playerkey, level.Value)
local expReq = Instance.new("IntValue", leaderstats)
expReq.Name = "expReq"
expReq.Value = ExpStore:GetAsync(playerkey) or 100
ExpStore:SetAsync(playerkey, expReq.Value)
local autoIncome = Instance.new("IntValue", leaderstats)
autoIncome.Name = "Income"
autoIncome.Value = IncomeStore:GetAsync(playerkey) or 0
IncomeStore:SetAsync(playerkey, autoIncome.Value)
local mng1 = Instance.new("IntValue", leaderstats)
mng1.Name = "mng1"
mng1.Value = mng1Store:GetAsync(playerkey) or 0
mng1Store:SetAsync(playerkey, mng1.Value)
local mng10 = Instance.new("IntValue", leaderstats)
mng10.Name = "mng10"
mng10.Value = mng1Store:GetAsync(playerkey) or 0
mng10Store:SetAsync(playerkey, mng10.Value)
local mng100 = Instance.new("IntValue", leaderstats)
mng100.Name = "mng100"
mng100.Value = mng1Store:GetAsync(playerkey) or 0
mng100Store:SetAsync(playerkey, mng100.Value)
local mng1000 = Instance.new("IntValue", leaderstats)
mng1000.Name = "mng1000"
mng1000.Value = mng1Store:GetAsync(playerkey) or 0
mng1000Store:SetAsync(playerkey, mng1000.Value)
local mng10000 = Instance.new("IntValue", leaderstats)
mng10000.Name = "mng10000"
mng10000.Value = mng1Store:GetAsync(playerkey) or 0
mng10000Store:SetAsync(playerkey, mng10000.Value)
local mng100000 = Instance.new("IntValue", leaderstats)
mng100000.Name = "mng100000"
mng100000.Value = mng1Store:GetAsync(playerkey) or 0
mng100000Store:SetAsync(playerkey, mng100000.Value)
local function updateStats()
MoneyStore:SetAsync(playerkey, money.Value)
LevelStore:SetAsync(playerkey, level.Value)
ExpStore:SetAsync(playerkey, expReq.Value)
IncomeStore:SetAsync(playerkey, autoIncome.Value)
mng1Store:SetAsync(playerkey, mng1.Value)
mng10Store:SetAsync(playerkey, mng10.Value)
mng100Store:SetAsync(playerkey, mng100.Value)
mng1000Store:SetAsync(playerkey, mng1000.Value)
mng10000Store:SetAsync(playerkey, mng10000.Value)
mng100000Store:SetAsync(playerkey, mng100000.Value)
print("Updated")
end
money.Changed:Connect(function()
if money.Value > expReq.Value then
level.Value = level.Value+1
expReq.Value = expReq.Value*1.2
print("money is greater than moneyreq")
end
end)
game.Players.PlayerRemoving:Connect(updateStats)
end)