basically, i made a generic loop that finds int values, and if their Value is 0 then it does things.
How can I only do things for only 1 of them? child[number] returns an error that says number is not a valid member of child.
FindFirstChildOfClass() also doesn't work because I need to find one with a specific value of 0.
help pls
part of the script:
for i,c in pairs (some directory:GetChildren()) do if c:IsA("IntValue") then if c.Value==0 then -- idk what to do now end end end
Try this:
function getNumber(tbl) for i,v in pairs(tbl) do if v==0 then return i,v end end return nil end --[[The getNumber function will use a generic for loop to go through all the values of **tbl**, and will return the key and value of a value if it's 0. The function will end when any value in **tbl** is 0, or when the for loop goes through all values in the table. If there are no values found that are equal to 0, the function will return nil --]] --Usage local Table = { 1, 2, 0, 3, 4 } local k,v = getNumber(Table) print(k,v) -- Will print 3,0, because a 0 has been found in the 3rd key of the table, and 0 is its value. If the 3rd key was 5, the function will return nil, nil.
For what you want, you could set tbl to the values of the IntValues:
local tbl = {} for _,v in pairs(something:GetChildren()) do if v:IsA('IntValue') then tbl[#tbl+1] = v.Value end end
You could just have a Boolean and only do stuff if it is false and once it does stuff to the first value it gets set to true like so:
Local boolCheck = false for i,c in pairs (some directory:GetChildren()) do If boolCheck == false then -- continue searching if it hasn't found a zero yet if c:IsA("IntValue") then if c.Value==0 then BoolCheck = true -- change to false to stop iterating end end end end