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

[UNSOLVED] Why Does My DataStore Not Work With My Global LeaderBoard?

Asked by 2 years ago
Edited 2 years ago

I Have A Global Leaderboard And Leaderstats They Work Just Fine But When I Added A DataStore To Save The Data It Shows The Leaderstat as 0 And Doesn't Show Anything Here Are My Scripts:

This Is The Leaderstats And DataStore Script

01local dataStoreService = game:GetService('DataStoreService')
02local myDataStore = dataStoreService:GetOrderedDataStore('WinsLeaderBoard')
03 
04game.Players.PlayerAdded:Connect(function(player)
05    local leaderstats = Instance.new('Folder')
06    leaderstats.Name = 'leaderstats'
07    leaderstats.Parent = player
08 
09    local Wins = Instance.new('IntValue')
10    Wins.Name = 'Wins'
11    Wins.Parent = leaderstats
12    Wins.Value = 11
13 
14    local Coins = Instance.new('IntValue')
15    Coins.Name = 'Coins'
View all 42 lines...

This Is The Script For The LeaderBoard

01local DataStoreService = game:GetService('DataStoreService')
02local WinsDataStore = DataStoreService:GetOrderedDataStore('WinsLeaderBoard')
03 
04local LeaderBoardPart = script.Parent.Parent.Parent
05local RefreshRate = 10
06 
07local function RefreshLeaderboard()
08 
09    for i,Player in pairs(game.Players:GetPlayers()) do
10        WinsDataStore:SetAsync(Player.UserId, Player.leaderstats.Wins.Value)
11    end
12 
13    local Success, Error = pcall(function()
14 
15        local Data = WinsDataStore:GetSortedAsync(false, 10)
View all 47 lines...

Thanks.

2 answers

Log in to vote
2
Answered by 2 years ago

Try seperating the datastore and the leaderstats and the leaderboard. Here is a fresh datastore if it helps:

01local dataStoreService = game:GetService("DataStoreService")
02local leaderstatsDataStore = dataStoreService:GetGlobalDataStore("leaderstats")
03 
04local loaded = {}
05 
06game.Players.PlayerAdded:Connect(function(player)
07    local leaderstats = player:WaitForChild("leaderstats")
08    if player.UserId > 0 and player.Parent then
09        local leaderstatsdata = leaderstatsDataStore:GetAsync(player.UserId)   
10        if leaderstatsdata ~= "Request Rejected" then
11            if leaderstatsdata then        
12                for i, stat in ipairs(leaderstats:GetChildren()) do
13                    local value = leaderstatsdata[stat.Name]
14                    if value then
15                        stat.Value = value
View all 37 lines...

Hope this helps!!!!

Ad
Log in to vote
0
Answered by 2 years ago

I tried This But It Still Does Not Show Anything On The LeaderStats Or Leaderboard, Thanks.

Answer this question