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

What is stopping this script from creating a leader board?

local currencyName = "Money" --Name the currency
local Datastore = game:GetService("DataStoreService"):GetDataStore("TestDataStore") --Stores The Amount

game.Players.PlayerAdded:Connect(function(player) --next few lines add the leaderboard data

    local folder = Instance.new("Folder")
    folder.Name = "leaderstats"
    folder.Parent = player

    local currency = Instance.new("IntValue")
    currency.Name = currencyName --takes the name of your currency and adds it into the leaderboard
    currency.Parent = folder

    local ID = currencyName.."-"..player.UserId
    local savedData = nil

    pcall(function()
        savedData = DataStore:Async(ID)
    end)

    if savedData ~= nil then
        currency.Value = savedData
        print("Data Loaded") --Tells that data has loaded
    else
    -- If New Player Loads The Following
    currency.Value = 50
    print("New Player To The Game")
    end


end)

game.Players.Removing:Connect(function(player)
    local ID = currencyName.."-"..player.UserId
    DataStore:SetAsync(Id,player.leaderstats [currencyName] .Value)
end)

game:BindToClose(function()

    --Starts when Server Shutsdown

    for i, player in pairs (game.Players:GetPlayers()) do
        if player then
            player:Kick("This Server Has Started To Shutdown. Please do rejoin") --the message it gives you
        end
    end

    wait(5) --waits 5 seconds so they can read the message then kicks them

end~~~~~~~~~~~~~~~~~


2 answers

You actually had everything correct except you forgot to add a value for your IntValue. It would go here:

local currency = Instance.new("IntValue")
currency.Name = currencyName
currency.Parent = player
--This is the line you need to add
currency.Value = 0
local currencyName = "Money" --Name the currency
local Datastore = game:GetService("DataStoreService"):GetDataStore("TestDataStore") --Stores The Amount

game.Players.PlayerAdded:Connect(function(player) --next few lines add the leaderboard data

    local folder = Instance.new("Folder")
    folder.Name = "leaderstats"
    folder.Parent = player

    local currency = Instance.new("IntValue")
    currency.Name = currencyName --takes the name of your currency and adds it into the leaderboard
    currency.Parent = folder
    currency.Value = 0

    local ID = currencyName.."-"..player.UserId
    local savedData = nil

    pcall(function()
        savedData = DataStore:Async(ID)
    end)

    if savedData ~= nil then
        currency.Value = savedData
        print("Data Loaded") --Tells that data has loaded
    else
    -- If New Player Loads The Following
    currency.Value = 50
    print("New Player To The Game")
    end


end)

game.Players.Removing:Connect(function(player)
    local ID = currencyName.."-"..player.UserId
    DataStore:SetAsync(Id,player.leaderstats [currencyName] .Value)
end)

game:BindToClose(function()

    --Starts when Server Shutsdown

    for i, player in pairs (game.Players:GetPlayers()) do
        if player then
            player:Kick("This Server Has Started To Shutdown. Please do rejoin") --the message it gives you
        end
    end

    wait(5) --waits 5 seconds so they can read the message then kicks them

end~~~~~~~~~~~~~~~~~

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