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

Help with leaderstats?

Asked by
FiredDusk 1466 Moderation Voter
8 years ago

The problem is, the leaderstats/Leaderboard does not come up.

local GVs=game.Workspace.GameValues

local DataStore=game:GetService("DataStoreService"):GetDataStore("LavaRise")
local Started=false

game.Players.PlayerAdded:connect(function(Plr)
    repeat wait() until Plr.Character
    Plr.NameDisplayDistance=0
    Plr.HealthDisplayDistance=0
    local AFKValue=Instance.new("BoolValue",Plr)
    AFKValue.Name="Afk"
    local stats=Instance.new("IntValue",Plr)
    stats.Name="leaderstats"
    local Level=Instance.new("NumberValue",stats)
    Level.Name="Level"
    local Wins=Instance.new("NumberValue",stats)
    Wins.Name="Wins"
    local Coins=Instance.new("NumberValue",stats)
    Coins.Name="Coins"
    local Key="Lava Rise Leaderstats - " ..Plr.userId
    local StatsTable=DataStore:GetAsync(Key)
    if not StatsTable then
        StatsTable={0,0,0} --{Level,Wins,Coins}
        DataStore:SetAsync(Key,StatsTable)
    else
        Level.Value=StatsTable[1]
        Wins.Value=StatsTable[2]
        Coins.Value=StatsTable[3]
    end
    if Started==false then
        GVs.LobbyTimer.Value=GVs.LobbyTimer.Time.Value
        GVs.LobbyTimer.CountingDown.Value=true
        Started=true
    end
end)

game.Players.PlayerRemoving:connect(function(Plr)
    local Key="Lava Rise Leaderstats - "..Plr.userId
    local StatsTable={Plr.leaderstats.Level.Value,Plr.leaderstats.Wins.Value,Plr.leaderstats.Coins.Value}
    DataStore:SetAsync(Key,StatsTable)
end)
0
Errors? There seems to be nothing wrong with your code. TheDeadlyPanther 2460 — 8y

1 answer

Log in to vote
1
Answered by
XAXA 1569 Moderation Voter
8 years ago

Set the parent of leaderstats last, after adding other values such as Level, Wins, and Coins.

From line 12 to line 19:

    local stats=Instance.new("IntValue")
    stats.Name="leaderstats"
    local Level=Instance.new("NumberValue",stats)
    Level.Name="Level"
    local Wins=Instance.new("NumberValue",stats)
    Wins.Name="Wins"
    local Coins=Instance.new("NumberValue",stats)
    Coins.Name="Coins"
    stats.Parent = Plr -- set the parent of leaderstats last.
Ad

Answer this question