I need my data store to stop giving random stats and ensure data loss does not happen. I recently released a game and a lot of the players complained about Dataloss and them being given random stats
local x = require(game.ReplicatedStorage.EternityNum)
local Data = game:GetService("DataStoreService"):GetDataStore("ButtonSim2")
game.Players.PlayerAdded:Connect(function(plr)
local s = Instance.new("Folder", plr)
s.Name = "Stats"
local ls = Instance.new("Folder", plr)
ls.Name = "leaderstats"
local money = Instance.new("StringValue", s)
money.Name = "Money"
money.Value = 0
local multi = Instance.new("StringValue", s)
multi.Name = "Multi"
multi.Value = 1
local reb = Instance.new("StringValue", s)
reb.Name= "Rebirth"
reb.Value = 0
local lvl = Instance.new("StringValue",s)
lvl.Name = "Level"
lvl.Value = "0"
local sup = Instance.new("StringValue", s)
sup.Name= "SuperRebirth"
sup.Value = 0
--RUNES
local com = Instance.new("StringValue", s)
com.Name= "Common"
com.Value = 0
local ucom = Instance.new("StringValue", s)
ucom.Name= "Uncommon"
ucom.Value = 0
local rare = Instance.new("StringValue", s)
rare.Name= "Rare"
rare.Value = 0
local epic = Instance.new("StringValue", s)
epic.Name= "Epic"
epic.Value = 0
local leg = Instance.new("StringValue", s)
leg.Name= "Legendary"
leg.Value = 0
--Geodes
local dirt = Instance.new("StringValue", s)
dirt.Name= "Dirt"
dirt.Value = 0
local stone = Instance.new("StringValue", s)
stone.Name= "Stone"
stone.Value = 0
local diamond = Instance.new("StringValue", s)
diamond.Name= "Diamond"
diamond.Value = 0
--Reset Layers
local ascension = Instance.new("StringValue", s)
ascension.Name= "Ascension"
ascension.Value = 0
--Passes
local statmast = Instance.new("StringValue", s)
statmast.Name= "StatMaster"
statmast.Value = 0
local vip = Instance.new("StringValue", s)
vip.Name= "VIP"
vip.Value = 0
local mvp = Instance.new("StringValue", s)
mvp.Name= "MVP"
mvp.Value = 0
local runemast = Instance.new("StringValue", s)
runemast.Name= "RuneMaster"
runemast.Value = 0
local geodemast = Instance.new("StringValue", s)
geodemast.Name= "GeodeMaster"
geodemast.Value = 0
--Leaderboard Stats
local runesopened = Instance.new("StringValue", s)
runesopened.Name= "RunesOpened"
runesopened.Value = 0
local geodesopened = Instance.new("StringValue", s)
geodesopened.Name= "GeodesOpened"
geodesopened.Value = 0
local dataload = Data:GetAsync(tostring(plr.UserId))
if dataload then
money.Value = dataload[1] or 0
multi.Value = dataload[2] or 1
reb.Value = dataload[3] or 0
com.Value = dataload[4] or 0
ucom.Value = dataload[5] or 0
rare.Value = dataload[6] or 0
epic.Value = dataload[7] or 0
leg.Value = dataload[8] or 0
dirt.Value = dataload[9] or 0
stone.Value = dataload[10] or 0
diamond.Value = dataload[11] or 0
ascension.Value = dataload[12] or 0
statmast.Value = dataload[13] or 0
lvl.Value = dataload[14] or 0
sup.Value = dataload[15] or 0
vip.Value = dataload[16] or 0
mvp.Value = dataload[17] or 0
runemast.Value = dataload[18] or 0
geodemast.Value = dataload[19] or 0
runesopened.Value = dataload[20] or 0
geodesopened.Value = dataload[21] or 0
end
local MoneyBoosts = {
{Value = "Rebirth", Function = "Multiply", Number1 = {1,0}},
{Value = "Common", Function = "Multiply", Number1 = {0.001,0}},
{Value = "Uncommon", Function = "Multiply", Number1 = {0.005,0}},
{Value = "Rare", Function = "Multiply", Number1 = {0.01,0}},
{Value = "Epic", Function = "Multiply", Number1 = {0.05,0}},
{Value = "Legendary", Function = "Multiply", Number1 = {0.5,0}},
{Value = "VIP", Function = "Multiply", Number1 = {1.5,0}},
{Value = "MVP", Function = "Multiply", Number1 = {2,0}},
{Value = "StatMaster", Function = "Multiply", Number1 = {3,0}},
}
local function CalculateMultiplier(Element)
local array = MoneyBoosts[Element]
if array.Function == "Multiply" then
return x.add(x.mul(x.convert(s[array.Value].Value), array.Number1), {1,0})
elseif array.Function == "Power" then
return x.add(x.pow(x.convert(s[array.Value].Value), array.Number1), {1,0})
end
end
local function CalculateMoney()
local val = x.convert(0.5)
val = x.mul(val, x.convert(multi.Value))
for i = 1, #MoneyBoosts do
val = x.mul(val, CalculateMultiplier(i))
end
local svb = x.convert(money.Value)
svb = x.add(svb,val)
money.Value = x.bnumtostr(svb)
end
local function CalculateLevel(TableOfStats, Outcome)
for i, v in pairs(TableOfStats) do
Outcome = x.add(Outcome, x.mul(x.log10(x.add(v.Stat, {1, 0})), v.MultiplicationValue))
end
return Outcome
end
while wait() do
CalculateMoney()
lvl.Value = x.bnumtostr(CalculateLevel({
{Stat = x.convert(money.Value), MultiplicationValue = {2,0}},
{Stat = x.convert(multi.Value), MultiplicationValue = {4,0}},
{Stat = x.convert(reb.Value), MultiplicationValue = {8,0}},
}, 0))
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
Data:SetAsync(tostring(plr.UserId),{
plr.Stats.Money.Value,
plr.Stats.Multi.Value,
plr.Stats.Rebirth.Value,
plr.Stats.Common.Value,
plr.Stats.Uncommon.Value,
plr.Stats.Rare.Value,
plr.Stats.Epic.Value,
plr.Stats.Legendary.Value,
plr.Stats.Dirt.Value,
plr.Stats.Stone.Value,
plr.Stats.Diamond.Value,
plr.Stats.Ascension.Value,
plr.Stats.StatMaster.Value,
plr.Stats.SuperRebirth.Value,
plr.Stats.VIP.Value,
plr.Stats.MVP.Value,
plr.Stats.RuneMaster.Value,
plr.Stats.GeodeMaster.Value,
plr.Stats.RunesOpened.Value,
plr.Stats.GeodesOpened.Value,
plr.Stats.Level.Value,})
end)