Tonumber() not working

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’m trying to make a leader board.
  2. What is the issue? Include screenshots / videos if possible!
    The tonumber function isn’t working.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I haven’t
    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!
		local PlrUsername = game.Players:GetNameFromUserIdAsync(tonumber(Data.key))

If you want the full script then say it bellow and i’ll give it to you.
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.

What is Data.key? The issue will be that either the string provided isn’t able to translate to numbers or that it isn’t an Id to begin with.

soo u want the full script???

I just want to know what data.key is, and if you have to post the whole script then go 4 it.

here’s the script

local DataStoreService = game:GetService("DataStoreService")

local HolderFrame = game.Workspace.WinsLeaderboard.BoardPart.LeaderBoardGui:WaitForChild("HolderFrame")
local WinsInfo = DataStoreService:GetOrderedDataStore("WinsDataStore")
local function UpdateBoard()

		local WinsData = WinsInfo:GetSortedAsync(false,5)
	local WinsPage = WinsData:GetCurrentPage()
	local Success, ErorrMessage = pcall(function()
	for Rank, Data in ipairs(WinsPage) do
			local PlrUsername = game.Players:GetNameFromUserIdAsync(tonumber(Data.key))
			local Name = PlrUsername
			local Wins = Data.Value
			local IsOnLeaderboard = false
			for i,v in pairs(game.Workspace.WinsLeaderboard.BoardPart.LeaderBoardGui.HolderFrame:GetChildren()) do
				if v.Name == "PlayerAddedFrame" and v.PlrName.Text == Name then
					IsOnLeaderboard = true
				end
			end
			if Wins and IsOnLeaderboard == false then
				local NewLeaderboardFrame = game.ReplicatedStorage.LeaderBoardStuff.WinsLeaderBoardFolder.LeaderBoardFrame:Clone()
				NewLeaderboardFrame.PlrName.Text = Name
				NewLeaderboardFrame.PlrWins.Text = Wins
				NewLeaderboardFrame.PlrRank.Text = "#" .. Rank
				NewLeaderboardFrame.Parent = game.Workspace.WinsLeaderboard.BoardPart.LeaderBoardGui.HolderFrame
			
			end
		
		end
end)
	if not Success  then
		warn("Something went wrong while updating the leaderboard. " .. ErorrMessage)
	end
end
while true do
	
	for _, Plr in pairs(game.Players:GetPlayers()) do
WinsInfo:SetAsync("Player_" .. Plr.UserId , Plr.leaderstats.Wins.Value)
	end
	for _, Frame in pairs(HolderFrame:GetChildren()) do
		if Frame:IsA("Frame") then
			Frame:Destroy()
		end
	
	end


	wait(10)
	UpdateBoard()
	print("Updated!")
	
end

The same problem is still there. Either Data.key isn’t a string that can be translated to a number, or it isn’t a userId.

the error detects it to the tonumber() line

Try printing Data.key, what is outputted?

1 Like