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 7 years ago

My code:

01function onEnter(player)
02 
03    local ld = Instance.new("IntValue")
04    ld.Parent = player
05    ld.Name = "leaderstats"
06    local value1 = Instance.new("IntValue")
07    value1.Parent = ld
08    value1.Name = "Points"
09    value1.Value = game.DataStoreService:Get
10 
11end
12 
13game.Players.PlayerAdded:connect(onEnter)
14 
15for i,v in pairs(game.Players:GetChildren()) do -- So that it works in Play Solo.
16    onEnter(v)
17end

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 — 7y

2 answers

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

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

01local DataStore = game:GetService("DataStoreService")
02local ds = DataStore:GetDataStore("PointsSave")
03game.Players.PlayerAdded:connect(function(player)
04local leader = Instance.new("Folder",player)
05leader.Name = "leaderstats"
06local Cash = Instance.new("IntValue",leader)
07Cash.Name = "Points" --Name of your leaderstat
08Cash.Value = ds:GetAsync(player.UserId) or 100 --Change to how much points the player will start out with
09ds:SetAsync(player.UserId, Cash.Value)
10Cash.Changed:connect(function()
11ds:SetAsync(player.UserId, Cash.Value)
12end)
13end)
14 
15 
16game.Players.PlayerRemoving:connect(function(player)
17ds:SetAsync(player.UserId, player.leaderstats.Points.Value)
18end)

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
7 years ago

Just put .Parent before .Name

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

Do that with every other stat too

Answer this question