Function not working

Im trying to get the leaderstats of a player but my function doent work.

function GetStats()
	for _,v in next,Players:GetChildren() do
		for _,c in next,v:WaitForChild("leaderstats"):GetChildren() do
			if c:IsA("NumberValue") then
				for _,vx in pairs(c) do
					print(vx.Value)
				end
			end
		end
	end
end

What am i doing wrong?

1 Like

numbervalue is not a table
30char

Im trying to see if the item it gets is a NumberValue

if c:IsA("NumberValue") then
				for _,vx in pairs(c) do
					print(vx.Value)
				end
			end

here

1 Like

Here is the error i get Players.MasonX890.PlayerGui.ScreenGui.LocalScript:29: invalid argument #1 to ‘pairs’ (table expected, got Instance)

Use Instance:GetChildren(). Instance is not a table. So you can’t loop through it.

You should use c:GetChildren() to get its childrens, also you can use Players:GetPlayers() instead of Players:GetChildren()

local players = game:GetService("Players")

local function getStats()
	for _, player in ipairs(players:GetPlayers()) do
		local leaderstats = player:FindFirstChild"leaderstats"
		if leaderstats then
			for _, stat in ipairs(leaderstats:GetChildren()) do
				if stat:IsA"ValueBase" then
					if stat:IsA"NumberValue" or stat:IsA"IntValue" then
						--Do code.
					end
				end
			end
		end
	end
end