Hello everyone I am trying to find a relationship between two tables and I am finding it very difficult.
The first table is a set of values which consist of primarily values that will be used for WalkSpeed.
local tab = {10,20,30,40,50}
The second table is a set of values which consist of values primarily for MaxHealth.
local tab2 = {5,10,15,20,25}
Is there a possible way of finding relationships between these two corresponding tables. Such as 10 and/or 20 appearing in both tables. Any help would be very much appreciated, thank you in advance.
local Array1 = {10,20,30,40,50} local Array2 = {5,10,15,20,25} local ValuesInCommon = {} for _,v in pairs(Array1) do for i = 1,#Array2 do if v == Array2[i] then ValuesInCommon[#ValuesInCommon + 1] = v end end end print(unpack(ValuesInCommon))
10 20
Here is why this works:
We start by creating an table to hold all values that are found to be in common. We then move into a for loop that will represent each Array value (v) separately. Because we are indexing each value separately - we can compare them one at a time to Array2, which is what the second for loop does. It will check if an Array1 value, v, is the same as any values from Array2, and if they are move them into the ValuesInCommon table.
You'll need to define what you're looking for first, only then can you look for it.