Why doesnt this work? Stats script and global leaderboard script.
This question has been solved by the original poster.
01 | local DataStore = game:GetService( "DataStoreService" ) |
05 | local ds 1 = DataStore:GetOrderedDataStore( "Survivals" ) |
06 | local ds 2 = DataStore:GetOrderedDataStore( "TopSurvivals" ) |
08 | game.Players.PlayerAdded:Connect( function (player) |
12 | local leaderstats = Instance.new( "Folder" , player) |
13 | leaderstats.Name = "leaderstats" |
15 | local survivals = Instance.new( "IntValue" , leaderstats) |
16 | survivals.Name = "Survivals" |
18 | local survivalsVal = ds 2 :GetAsync(player.UserId) |
20 | survivals.Value = ds 1 :GetAsync(player.UserId) or 0 |
21 | ds 1 :SetAsync(player.UserId, survivals.Value) |
24 | survivals.Changed:Connect( function () |
27 | ds 1 :SetAsync(player.UserId, survivals.Value) |
28 | print (player.UserId.. "'s Data of" ..survivals.Value.. " " ..survivals.Name.. " has been saved" ) |
30 | ds 2 :SetAsync(player.UserId, survivals.Value) |
36 | game.Players.PlayerRemoving:Connect( function (player) |
37 | local survivals = player.leaderstats.Survivals |
39 | ds 1 :SetAsync(player.UserId, player.leaderstats.Survivals.Value) |
40 | print (player.UserId.. "'s Data of" ..player.leaderstats.Survivals.Value.. " " ..player.leaderstats.Survivals.Value.. " has been saved" ) |
41 | ds 2 :SetAsync(player.UserId, survivals.Value) |
02 | local ds 1 = game:GetService( 'DataStoreService' ):GetOrderedDataStore( "TopSurvivals" ) |
06 | local Ascending = false |
08 | local pages = ds 1 :GetSortedAsync(Ascending, PageSize) |
09 | local CurrentPage = pages:GetCurrentPage() |
11 | for i,v in pairs (script.Parent:GetChildren()) do |
13 | if v.Name ~ = "Label" and v ~ = script then |
21 | for i,v in ipairs (CurrentPage) do |
25 | local text = script.Parent:FindFirstChild( "Position" .. i) |
27 | text.Username.Text = game.Players:GetNameFromUserIdAsync(key) |
28 | text.Survivals.Text = value |