I have this script, but the stats only appear for the first person to join, by this I mean the 1st person to join gets their stats on the leaderboard but the others just have blank spots. How can I fix this? Here is my code.
local ds=game:GetService("DataStoreService"):GetDataStore("Stats")
game.Players.PlayerAdded:connect(function(np)
local ls=Instance.new("BoolValue")
ls.Name="leaderstats"
local level=Instance.new("NumberValue")
level.Name="Level"
local xp=Instance.new("NumberValue")
xp.Name="XP"
xp.Parent=ls
local kills=Instance.new("NumberValue")
kills.Name="Kills"
kills.Parent=ls
level.Parent=ls
ls.Parent=np
kills.Value=0
level.Value=0
xp.Value=0
dsl=ds:GetAsync(tostring(np.userid).."Level")
if dsl==nil then
ds:SetAsync(tostring(np.userid).."Level", 0)
else
level.Value=ds:GetAsync(tostring(np.Userid).."Level")
end
dsxp=ds:GetAsync(tostring(np.userid).."XP")
if dsxp==nil then
ds:SetAsync(tostring(np.userid).."XP", 0)
else
xp.Value=ds:GetAsync(tostring(userid).."XP")
end
end)
game.Players.PlayerRemoving:connect(function(lp)
level=lp.leaderstats.Level
ds:SetAsync(tostring(lp.userid).."Level", level.Value)
ds:SetAsync(tostring(lp.userid).."XP", xp.Value)
end)
game.Players.PlayerAdded:connect(function(player)
player.CharacterAdded:connect(function(character)
local humanoid=character:WaitForChild("Humanoid")
humanoid.Died:connect(function()
local value=humanoid:FindFirstChild("creator")
local kp=value.Value
if kp~=nil then
kp.leaderstats.Kills.Value=kp.leaderstats.Kills.Value +1
kp.leaderstats.XP.Value=kp.leaderstats.XP.Value + 10
local xpn=kp.leaderstats.Level.Value * 100
if kp.leaderstats.XP.Value >= xpn then
kp.leaderstats.Level.Value=kp.leaderstats.Level.Value +1
ds:SetAsync(tostring(kp.userid).."Level", kp.leaderstats.Level.Value)
ds:SetAsync(tostring(kp.userid).."XP", kp.leaderstats.XP.Value)
end
end
end)
end)
end)
