Hey Everyone,
Quick Question:
How can i loop on every IntValue and check what is the highest value of the loop (in paris)
Thanks.
Hey Everyone,
Quick Question:
How can i loop on every IntValue and check what is the highest value of the loop (in paris)
Thanks.
do you know the highest value?
I loop on every value in the folder but how can i check what is the highest value
local function CountBid()
for i, v in pairs(game.ServerStorage.Bids:GetChildren()) do
end
end
do you know what the highest value is?
Since if it’s an array, you should use ipairs
to have everything in order.
In that case you can check if i
equals the length of the array:
for i, v in ipairs(array) do
if i == #array then
--max val
end
end
No, I don’t know what is the highest value
It’s Folder with IntValue of every player
local values = {}
for _,x in pairs(game:GetService("Players"):GetChildren()) do
if not x:FindFirstChild("IntValue") then return end
table.insert(values, x.Value)
end
for _,value in ipairs(values) do
if value == #values then
-- you have your max val, which is the variable **value**
print(tostring(value))
end
end
I added off of @TheCarbyneUniverse 's reply.
Why shouldn’t you use in pairs
?
You can use pairs
, nothing wrong in that. In fact, when you aren’t sure if certain values in-between are nil, then it’s safer to use pairs
.
local arr = {'1', 19, true, nil, 'hello', 109882}
for _, v in pairs(arr) do
print(v)
end
--print everything except nil
for _, v in ipairs(arr) do
print(v)
end
--print everything UP TO nil ('1', 19, true)
So, ipairs
stops when it hits nil. But, in the case of arrays where you know that no values are nil in-between (such as in this case with :GetChildren()), it’d be better to use ipairs
as it’s more specialized. Plus, it runs it in order.
Interesting, but pairs
should run in order…
local Table = {'a','b','c'}
for i,v in pairs(Table) do
print(v)
end
-- Output:
-- a
-- b
-- c
…right?