Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

why won't my leaderboard work?

Can I get anyone to spot an error for me? It doesn't show when i play

scoreKey = "PlayerScore"
levelKey = "PlayerLevel"

function onPlayerEntered(newPlayer)
    if newPlayer.Name ~= "Player1" then
    newPlayer:WaitForDataReady()
    end

    local stats = Instance.new("IntValue")
    stats.Name = "leaderstats"

    local kills = Instance.new("IntValue")
    kills.Name = "Knockouts"

    local points = Instance.new("IntValue")
    points.Name = "Points"

    kills.Parent = stats
    points.Parent = stats
    stats.Parent = newPlayer    

    kills.Changed:connect(function() onXPChanged(newPlayer, kills, points) end)
    points.Changed:connect(function() onlevelChanged(newPlayer, kills, points) end) 
    newPlayer.Changed:connect(function (property) end)

local ok, ret = pcall(function() return newPlayer:LoadNumber(scoreKey) end)
    if ok then
        if ret ~= 0 then
            kills.Value = ret
        else
            print("Nothing to load/score was 0")
        end
    else
        print("Error:", ret)
    end

    local ok2, ret1 = pcall(function() return newPlayer:LoadNumber(levelKey) end)
    if ok2 then
        if ret1 ~= 0 then
            points.Value = ret1
        else
            print("Nothing to load/score was 0")
            end
    else
        print("Error:", ret1)
    end


1 answer

"if newPlayer.Name ~= "Player1" then newPlayer:WaitForDataReady()"

Are you trying to do it in Play Solo? If so, WaitForDataReady does not work in Play Solo.

This discussion is preserved as it was. New answers, comments, and votes are closed.