I have a problem with a script I’m doing for a top leaderboard, the Output tells me:
“attempt to compare number with nil”, How can I solve that ?
Why is “v” nil ?
Script:
local SurfaceGui = script.Parent
local Holder = script.Parent.Frame.ScrollingFrame
function Main ()
local Success, Error = pcall(function()
local Pages = OrderedDataStore:GetSortedAsync(false, 10)
local Data = Pages:GetCurrentPage()
for k, v in pairs(Data)do
if tonumber(v.key) >= 1 then
local PlayerName = game.Players:GetNameFromUserIdAsync(v.Key)
local Level = tostring(v.Value)
print(PlayerName, Level)
local NewFrame = script.Frame:Clone()
NewFrame.PlayerPos.Text = k..". "..PlayerName
NewFrame.PlayerCurrency = "Nivel "..Level
NewFrame.Parent = Holder
end
end
end)
if not Success then
error(Error)
end
end
while true do
for _, Player in pairs(game.Players:GetChildren())do
local PlayerValue = Player.leaderstats.Nivel.Value
OrderedDataStore:SetAsync(Player.UserId, PlayerValue)
end
Main()
wait(10)
end```