Hi,
I made a DataStore leaderboard but it doesnt save. And the leaderstats after extralevel
doesn't work. Anybody know what is wrong?
local DataRank = game:GetService("DataStoreService"):GetDataStore("RankStore")
local DataXP = game:GetService("DataStoreService"):GetDataStore("XPStore")
local DataJa = game:GetService("DataStoreService"):GetDataStore("JaStore")
local DataNee = game:GetService("DataStoreService"):GetDataStore("NeeStore")
local DataGeld = game:GetService("DataStoreService"):GetDataStore("GeldStore")
local DataMunt = game:GetService("DataStoreService"):GetDataStore("MuntStore")
local DataTrofee = game:GetService("DataStoreService"):GetDataStore("TrofeeStore")
local DataGe = game:GetService("DataStoreService"):GetDataStore("GeStore")
local maxlevel = 250
game.Players.PlayerAdded:connect(function(player)
local stats = Instance.new("IntValue", player)
stats.Name = "leaderstats"
local level = Instance.new("IntValue", stats)
level.Name = "Level"
level.Value = 1
local expp = Instance.new("IntValue", stats)
expp.Name = "XOP"
expp.Value = 0 while wait()
do local extralevel = level.Value
local expneed = ((extralevel * 2) - 1) * 50
if level.Value < maxlevel then
if expp.Value >= expneed then level.Value = level.Value + 1
expp.Value = expp.Value - expneed
end
end
end
local win = Instance.new('IntValue', stats)
win.Name = "QW" -- Wins (Dd)
win.Value = 0
local lose = Instance.new('IntValue', stats)
lose.Name = "LP" -- Loses (De)
lose.Value = 0
local money = Instance.new('IntValue', stats)
money.Name = "DHJK" -- Money (Df)
money.Value = 0
local coin = Instance.new('IntValue', stats)
coin.Name = "IPE" -- Coins (Dg)
coin.Value = 0
local trofee = Instance.new('IntValue', stats)
trofee.Name = "TR" -- Trofee (Dh)
trofee.Value = 0
local ge = Instance.new('IntValue', stats)
ge.Name = "KLOPT" -- Gems (Di)
ge.Value = 0
end)
game.Players.PlayerAdded:connect(function(player)
local Db = DataRank:GetAsync(tostring(player.userId)..":DB")
local Dc = DataXP:GetAsync(tostring(player.userId)..":DC")
local Dd = DataJa:GetAsync(tostring(player.userId)..":DD")
local De = DataNee:GetAsync(tostring(player.userId)..":DE")
local Df = DataGeld:GetAsync(tostring(player.userId)..":DF")
local Dg = DataMunt:GetAsync(tostring(player.userId)..":DG")
local Dh = DataTrofee:GetAsync(tostring(player.userId)..":DH")
local Di = DataGe:GetAsync(tostring(player.userId)..":DI")
if Db then level.Value = Db end
if Dc then expp.Value = Dc end
if Dd then win.Value = Dd end
if De then lose.Value = De end
if Df then money.Value = Df end
if Dg then coin.Value = Dg end
if Dh then trofee.Value = Dh end
if Di then ge.Value = Di end
end)
game.Players.PlayerRemoving:connect(function(player)
local Stats = player:FindFirstChild("leaderstats")
if Stats then
local DBB = Stats:FindFirstChild("Level")
local DCC = Stats:FindFirstChild("XOP")
local DDD = Stats:FindFirstChild("QW")
local DEE = Stats:FindFirstChild("LP")
local DFF = Stats:FindFirstChild("DHJK")
local DGG = Stats:FindFirstChild("IPE")
local DHH = Stats:FindFirstChild("TR")
local DII = Stats:FindFirstChild("KLOPT")
if DBB then DataRank:SetAsync(tostring(player.userId)..":DB", level.Value) end
if DCC then DataXP:SetAsync(tostring(player.userId)..":DC", expp.Value) end
if DDD then DataJa:SetAsync(tostring(player.userId)..":DD", win.Value) end
if DEE then DataNee:SetAsync(tostring(player.userId)..":DE", lose.Value) end
if DFF then DataGeld:SetAsync(tostring(player.userId)..":DF", money.Value) end
if DGG then DataMunt:SetAsync(tostring(player.userId)..":DG", coin.Value) end
if DHH then DataTrofee:SetAsync(tostring(player.userId)..":DH", trofee.Value) end
if DII then DataGe:SetAsync(tostring(player.userId)..":DI", ge.Value) end
end
end)

2 comments
I'd find it more efficient to just use one datastore with the player's userId like this: local DS = game:GetService("DataStoreService"):GetDataStore(Player.userId.."DataStore") and when saving just do DS:SetAsync("POINT_NAME_GOES_HERE", POINTS_VALUE_GOES_HERE) so that way your script isn't cluttered with DataStores.
You could also equivilantly give each player their own scope, which I personally think makes it a little easier to organize. However It comes down to preference as lightpower26's way of doing it is just as effective.