[Help] Global Leaderboard

Ok so I’ve watched and looked at some tutorials on global leaderboard and they aren’t working for me. Could somebody help me with this? Also, this is 1 of the scripts

while true do

while true do

    for _, player in pairs(game.Players:GetPlayers()) do
          WinsLeaderboard:SetAsync(player.UserId, player.leaderstats.Wins.Value)
    end

    for _, frame in pairs (game.Workspace.GlobalLeaderboard.LeaderboardGUI.Holder:GetChildren()) do
          frame:Destroy()
    end

    updateLeaderboard()
    print(“Updated!”)

    wait(10)

end

In the output, it says string is not allowed in datastore. Please Help.

is “WinsLeaderboard” the DataStore name? Also you shouldn’t really put a for loop in a while loop.

while true do
    for _, player in pairs(game.Players:GetPlayers()) do
        WinsLeaderboard:SetAsync(player.UserId, player.leaderstats.Wins.Value)
end

Some Issues Here:

  1. Your While Loop has no Wait()
  2. Your datastore request isn’t wrapped in a pcall function
  3. Your For loop has no end statement

I suggest you decrease the times this data is saved to times when it is important (server shutdown, players leaving, etc). Then wrap your datastore in a pcall shown below. And add the end statement for your for loop.

PCall:

local success, err = pcall()

Now to fix your main issue use:

tonumber(player.leaderstats.Wins.Value)

Yes WinsLeaderboard is the datastore name

You’ll need to add an end and put a wait on the while loop

I edited the script for the full loop area where the error is.

I edited the post to show the full loop script where the error is.

A tutorial that I found helpful is this . This video is great and straight to the point. As for your script, there are many problems as @xZylter has stated.

I just showed the full area with the error lol i shouldn’t of left part of the script out.

Also that was the video i was watching and in output their is an error “String is not allowed in datastore” which i said in the post.

How do you put a link like that? Please tell me :smile:

You can use webhooks for that.
https://gyazo.com/c971d9e28771a10e7047b188868b7a80

1 Like

Thank you! :smiley: 30 Characters

Is it possible to see the entire script?

Yes, also ive double checked the entire script with the video its the same. The error is “string is not allowed in datastore” as I’ve said before. This is the part with the error “WinsLeaderboard:SetAsync(player.UserId, player.leaderstats.Wins.Value)”

What you are looking for is an OrderedDataStore. You can find information on how to create and use one here: OrderedDataStore | Documentation - Roblox Creator Hub

This is some sample code from the wiki:

local DataStoreService = game:GetService("DataStoreService")
local PointsODS = DataStoreService:GetOrderedDataStore("Points") 
 
local function printTopTenPlayers()
	local isAscending = false
	local pageSize = 10
	local pages = PointsODS:GetSortedAsync(isAscending, pageSize)
	local topTen = pages:GetCurrentPage()
 
	-- The data in 'topTen' is stored with the index being the index on the page
	-- For each item, 'data.key' is the key in the OrderedDataStore and 'data.value' is the value
	for rank, data in ipairs(topTen) do
		local name = data.key
		local points = data.value
		print(data.key .. " is ranked #" .. rank .. " with " .. data.value .. "points")
	end
 
	-- Potentially load the next page...
	--pages:AdvanceToNextPageAsync()
end
 
-- Create some data
PointsODS:SetAsync("Alex", 55)
PointsODS:SetAsync("Charley", 32)
PointsODS:SetAsync("Sydney", 68)
 
-- Display the top ten players
printTopTenPlayers()

This is because the value you are using is a StringValue, you can only use Integer values in datastores. A quick fix is to do this:

 WinsLeaderboard:SetAsync(player.UserId, tonumber(player.leaderstats.Wins.Value))

Ok ill try that later. 30 characters

1 Like