I am trying to loop through a dictionary of player stats, but am having trouble finding a way to make sure a value is a table vs a number value.
My Code:
Players[player]["Stats"] = {
Chest = {Pectorals = 1},
Arms = {Biceps = 1, Triceps = 1},
Legs = {Quads = 1, Glutes = 1, Hamstring = 1, Adductors = 1},
Core = {Abs = 1, LowerBack = 1},
}
Players[player]["Stats"]["Stats"] = Instance.new("Folder",player)
StatChangeEvent.OnServerEvent:Connect(function(plr)
local output = 0
local function loop()
for i,v in pairs(Players[plr]["Stats"]) do
if v[1] then
loop(v)
print(v[1])
elseif v then
output = output + v
print(v)
else
print("Failure")
end
end
end
loop()
local PowerLevel = output
plr.leaderstats["Power Level"].Value = PowerLevel
end)
end)

1 comment
You can use type(variable) == "number" to check if it is a number or not. Using tonumber(variable) could cause false positives where a string could be considered a number value, which could be exploited and cause bugs.