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

Leaderboards will not show up, can anyone help me as to why?

Asked by 6 years ago

My code:

function onEnter(player)

    local ld = Instance.new("IntValue")
    ld.Parent = player
    ld.Name = "leaderstats"
    local value1 = Instance.new("IntValue")
    value1.Parent = ld
    value1.Name = "Points"
    value1.Value = game.DataStoreService:Get

end

game.Players.PlayerAdded:connect(onEnter)

for i,v in pairs(game.Players:GetChildren()) do -- So that it works in Play Solo.
    onEnter(v)
end

Writing a currency system. Really don't want to make a gui just for "points" but will if need be.

If anyone knows why it won't work, I'd love to know.

Ran in Studio.

1
What the freak is "game.DataStoreService:Get" ? thesit123 509 — 6y

2 answers

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

You should use this as it creates the stat and saves it. Also, game.DataStoreService:Get isn't a thing.

local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("PointsSave")
game.Players.PlayerAdded:connect(function(player)
local leader = Instance.new("Folder",player)
leader.Name = "leaderstats"
local Cash = Instance.new("IntValue",leader)
Cash.Name = "Points" --Name of your leaderstat
Cash.Value = ds:GetAsync(player.UserId) or 100 --Change to how much points the player will start out with
ds:SetAsync(player.UserId, Cash.Value)
Cash.Changed:connect(function()
ds:SetAsync(player.UserId, Cash.Value)
end)
end)


game.Players.PlayerRemoving:connect(function(player)
ds:SetAsync(player.UserId, player.leaderstats.Points.Value)
end)

This script should go in the ServerScriptService. If this helped, please upvote and accept answer.

Ad
Log in to vote
1
Answered by
Bertox 159
6 years ago

Just put .Parent before .Name

local ld = Instance.new("IntValue")
ld.Name = "leaderstats"
ld.Parent = player

Do that with every other stat too

Answer this question