So, this script needs to do 3 things...
- Set up the player's leaderboard.
- Set the stats on the leaderboard to whatever the player has saved.
- Save the player's stats when they leave.
It doesn't even get to setting up the leaderboard.
Here's my script...
local myData = game:GetService("DataStoreService"):GetDataStore("GameStats")
local vals = {
{"Wins",0,"IntValue"},
{"BlitzCreditz" ,0,"IntValue"},
}
game.Players.PlayerAdded:connect(function(player)
local tab = myData:GetAsync(player.userId)
if not tab then -- new player set up table
tab = {}
local num = 0
for i = 1,#vals do
table.insert(tab,{vals[i][1],vals[i],2})
if num % 10 == 0 then -- reduces lag
wait()
end
end
end
myData:SetAsync(player.userId,tab)
local stats = Instance.new("IntValue",player)
stats.Name = "leaderstats"
local num = 0
for i = 1,#vals do
local val = Instance.new(vals[i][3],stats)
val.Name = vals[i][1]
val.Value = vals[i][2]
val.Parent = stats
if num % 10 == 0 then -- lag reducer if you have a lot of vals
wait()
end
end
game.Players.PlayerRemoving:connect(function(player)
local newTab = {}
local tab = myData:GetAsync(player.userId)
local num = 0
for i = 1,#tab do
num = num + 1
for a,b in pairs(player.leaderstats:GetChildren()) do
if b.Name == tab[i][1] then
table.insert(newTab,{tab[i][1],tab[i][2],tab[i][3]})
end
end
if num % 10 == 0 then
wait()
end
end
myData:SetAsync(player.userId,newTab)
end)
All help would be appreciated!

2 comments
I'm currently looking at your script, and you're making it more difficult then it needs to be. (Thought I should let you know)
Lol thanks. Any help would be appreciated!