Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I make this appear for every player on the leaderboard?

Asked by
ultrabug 306 Moderation Voter
10 years ago

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)

1 answer

Log in to vote
0
Answered by
RubenKan 3615 Moderation Voter Administrator Community Moderator
10 years ago

This means you made a typo somewhere around the end, that makes the script break, the only way to fix this is to look for that typo, so that it can re-enter within the function, i would suggest starting a roblox-studio server, and then joining via ALT+F7 so that you can easily find the line that the script is crashing

Ad

Answer this question