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

Why is this script not making a leaderboard in-game?

Asked by 10 years ago
local PlayerDataStore = require(game.ServerScriptService.PlayerDataStore)

Game.Players.PlayerAdded:connect(function(p)
    local saveData = PlayerDataStore:GetSaveData(p)

    local l = Instance.new("Model")
    l.Name = "leaderstats"
    local wins = Instance.new("IntValue", l)
    local creds = Instance.new("IntValue", l)
    creds.Name="Credits"
    wins.Name="Wins"

    if saveData:Get("Currency") then
        creds.Value=saveData:Get("Currency")
    else
        saveData:Set("Currency", 0)
        creds.Value=saveData:Get("Currency")
    end

    if saveData:Get("Victories") then
        creds.Value=saveData:Get("Victories")
    else
        saveData:Set("Victories", 0)
        creds.Value=saveData:Get("Victories")
    end

    wins.Parent=l
    creds.Parent=l

    creds.Changed:connect(function(val)     
        saveData:Set("Currency", val)
    end)
end)

2 answers

Log in to vote
1
Answered by 10 years ago

The parent of leaderstats should be set as the player. At Line 6:

-- Change: 
local l = Instance.new("Model")
-- To:
local l = Instance.new("Model", p)
0
Thanks, stupid mistake XD ThatChristianGuy 27 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

It doesn't work because it's wrong. This is correct:

local PlayerDataStore = require(game.ServerScriptService.PlayerDataStore)

game.Players.PlayerAdded:connect(function(p)
    repeat wait() until p.Character

    local saveData = PlayerDataStore:GetSaveData(p)
    local l = Instance.new("IntValue", p)
    l.Name = "leaderstats"

    local wins = Instance.new("IntValue", l)
    local creds = Instance.new("IntValue", l)
    wins.Name = "Wins"
    creds.Name = "Credits"

    --[[
        Rest of script goes here
    ]]

end)

Read this: http://wiki.roblox.com/index.php?title=SaveData_(Method)

Answer this question