Global leaderboard problem

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want the plrs rank value(value is a string) to save thru the datastore

  2. What is the issue? Include screenshots / videos if possible!

  3. What solutions have you tried so far? Did you look for solutions
    on the Developer Hub?
    i looked all over the developer hub tonumber seemed to work for everybody else but not me

i tried changing the name from rank to lvl and it still does the same thing

i have 2 global leaderboard that work just fine both are intvalues
and yes, i know it looks sloppy.
rank script:
wait(5)
local DSS = game:GetService(“DataStoreService”)
local RankDS = DSS:GetOrderedDataStore(“RankDatas”)

local GlobalBoard = script.Parent
local NewFlipUI = game.ReplicatedStorage.BestRankUI
local UpdateTime = 10
local k

local function comma_value(amount)
while true do
amount, k = string.gsub(amount, “^(-?%d+)(%d%d%d)”, ‘%1,%2’)
print(amount)
if (k==0) then
break
end
end
return amount
end

local stringg = “football” – test

tonumber(stringg,2)

local function UpdateBoard()

for i, plr in pairs(game.Players:GetChildren()) do
	local Lvl = plr.leaderstats:FindFirstChild("Lvl")
	if Lvl then
		local LvlValue = tonumber(Lvl.Value)
		RankDS:SetAsync(plr.UserId, LvlValue) -- this is where the problem is it prints arg 2 missing or nil every single time ive been trying to firgure this out for 1/2 hrs 
	end
	
end

local Success, Erorr = pcall(function()
	local Data = RankDS:GetSortedAsync(false,10)
	local SpentPage = Data:GetCurrentPage()

	for rank, SavedData in ipairs(SpentPage)  do

		local User = game.Players:GetNameFromUserIdAsync(tonumber(SavedData.key))
		local RRank = SavedData.value
		if RRank then
			
			local NewBoard = NewFlipUI:Clone()
			NewBoard.Parent = GlobalBoard.SurfaceGui.Frame.ScrollingFrame
			NewBoard.PlrName.Text = User
			NewBoard.Amount.Text = RRank
			print(RRank)
			NewBoard.Number.Text = rank
			
			print("yes")
		end
	end
	
end)

end

while true do

for _, Frame in pairs(GlobalBoard.SurfaceGui.Frame.ScrollingFrame:GetChildren()) do
	if Frame:IsA("Frame") then
		Frame:Destroy()
	end
end
UpdateBoard()
wait(UpdateTime)

end

if anybody knows could i use a intvalue instead of a string to save the plrs rank value which is a(string)

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

-- This is an example Lua code block

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

t seems like you’re trying to save players’ rank values using a DataStore. However, you mentioned that you’re encountering an issue with the RankDS:SetAsync() line where it says “arg 2 missing or nil”.

The error message suggests that the second argument you’re passing to RankDS:SetAsync() is either missing or nil. In your case, LvlValue might be nil or not getting the expected value. To troubleshoot this, you can add some print statements to check the value of LvlValue and ensure it’s not nil:

local LvlValue = tonumber(Lvl.Value)
print(LvlValue)
RankDS:SetAsync(plr.UserId, LvlValue)

every time I print the value of the rank value it always says nil, I tried it again and printed nil again.

i dont know if its the datastore or if its the 2 global leaderboards i have already

If the rank value is always printing as nil, it suggests that the Lvl.Value property is not being set correctly or doesn’t exist. Here are a few troubleshooting steps you can follow:

  1. Verify that the Lvl leaderstat exists for each player:
  • Check that the leaderstat name is correct (Lvl).
  • Ensure that the leaderstat is added to the player’s leaderstats folder correctly.

I checked if leaderstats and lvl is loaded and I printed the lvl value, but it still returns nil I did find a post about some characters are not used inside datastores or string?? I’m not sure.

can i see the leaderstats script

i see no errors now since i added the Plrs table. wait(5)
local DSS = game:GetService(“DataStoreService”)
local RankDS = DSS:GetOrderedDataStore(“RankDatass”)
local PlRS = {}

local GlobalBoard = script.Parent
local NewFlipUI = game.ReplicatedStorage.BestRankUI
local UpdateTime = 10
local k

local function comma_value(amount)
while true do
amount, k = string.gsub(amount, “^(-?%d+)(%d%d%d)”, ‘%1,%2’)
print(amount)
if (k==0) then
break
end
end
return amount
end

local stringg = “football” – test

tonumber(stringg,2)

local function UpdateBoard()

for i, plr in pairs(game.Players:GetChildren()) do
	local Lvl = plr.leaderstats:FindFirstChild("Lvl")
	if Lvl and plr.leaderstats then
		table.insert(PlRS,plr)
		print(Lvl.Value)
		if plr.Name[PlRS] then
			local LvlValue = tonumber(Lvl.Value)
			print(LvlValue)
			RankDS:SetAsync(plr.UserId, LvlValue)
		end
	end
	
end

local Success, Erorr = pcall(function()
	local Data = RankDS:GetSortedAsync(false,10)
	local SpentPage = Data:GetCurrentPage()

	for rank, SavedData in ipairs(SpentPage)  do

		local User = game.Players:GetNameFromUserIdAsync(tonumber(SavedData.key))
		local RRank = SavedData.value
		if RRank then
			
			local NewBoard = NewFlipUI:Clone()
			NewBoard.Parent = GlobalBoard.SurfaceGui.Frame.ScrollingFrame
			NewBoard.PlrName.Text = User
			NewBoard.Amount.Text = RRank
			print(RRank)
			NewBoard.Number.Text = rank
			
			print("yes")
		end
	end
	
end)

end

while true do

for _, Frame in pairs(GlobalBoard.SurfaceGui.Frame.ScrollingFrame:GetChildren()) do
	if Frame:IsA("Frame") then
		Frame:Destroy()
	end
end
UpdateBoard()
wait(UpdateTime)

end

for some reason the rest of the script is not working.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.