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:
1 | for i,c in pairs (some directory:GetChildren()) do |
2 | if c:IsA( "IntValue" ) then |
3 | if c.Value = = 0 then |
4 | -- idk what to do now |
5 | end |
6 | end |
7 | end |
Try this:
01 | function getNumber(tbl) |
02 | for i,v in pairs (tbl) do |
03 | if v = = 0 then |
04 | return i,v |
05 | end |
06 | end |
07 | return nil |
08 | end |
09 |
10 | --[[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 |
11 | --]] |
12 |
13 | --Usage |
14 |
15 | local Table = { |
For what you want, you could set tbl to the values of the IntValues:
1 | local tbl = { } |
2 | for _,v in pairs (something:GetChildren()) do |
3 | if v:IsA( 'IntValue' ) then |
4 | tbl [ #tbl+ 1 ] = v.Value |
5 | end |
6 | 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:
01 | Local boolCheck = false |
02 | for i,c in pairs (some directory:GetChildren()) do |
03 | If boolCheck = = false then -- continue searching if it hasn't found a zero yet |
04 | if c:IsA( "IntValue" ) then |
05 | if c.Value = = 0 then |
06 | BoolCheck = true -- change to false to stop iterating |
07 | end |
08 | end |
09 | end |
10 | end |