Alright, I have a table, and I want to see if all the values are the same. If all the values are the same, I want it to output the value, and if they aren't, I want nothing to happen.
If this helps. It's a territory control script. If all the IDs in the script are the same, it goes to that group. If they're not all the same, nothing happens.
01 | while true do |
02 | local factions = { } --Create an empty table to store the factions |
03 |
04 | --Add the values to the table |
05 | for i, child in pairs (script:GetChildren()) do |
06 | factions [ i ] = child.Value |
07 | end |
08 |
09 | --Do whatever I gotta do to check if they're all the same. |
10 |
11 | wait( 0.5 ) --Update twice a second |
12 | end |
Here is what you would do:
01 | while true do |
02 | local factions = { } --Create an empty table to store the factions |
03 |
04 | --Add the values to the table |
05 | for i, child in pairs (script:GetChildren()) do |
06 | factions [ i ] = child.Value |
07 | end |
08 |
09 | if #factions > 0 then |
10 | local check = factions [ 1 ] |
11 | --USE TAB TO INDENT COME ON NOW MY CODE IS GONNA BE MISALIGNED |
12 | local success = true |
13 | for _, compare in pairs (factions) do |
14 | if compare ~ = check then |
15 | success = false |
So what this does, is grab the first value of the table, and compare if the rest of the table is equivalent to the first value of the table. Also, READ MY BIO. Hope this helps!