I can't figure out how to do an simple algoritm to get the sum of two numbers

I am trying to find a solution to the problem “Two Sum” if you recognize it , and I’ve run into a problem and I cannot figure it out (Lua)

Code:

num = {2,7,11,15}
target = 9
current = 0 
repeat
  createNum1 = tonumber(num[math.random(1,#num)])
  createNum2 = tonumber(num[math.random(1,#num)])
  current = createNum1 + createNum2
until current == target
  print(table.find(num,createNum1), table.find(num,createNum2)) 

Error:

lua5.3: HelloWorld.lua:9: attempt to call a nil value (field 'find')
stack traceback:
    HelloWorld.lua:9: in main chunk
    [C]: in ?

Not made in Studio , Thanks for the time!

it’s saying that find isnt a function in table
that might be a Luau only function

also, about your implementation, you should also check if the 2 indexes are the same. I don’t think you can use the same number twice

I already found the solution , it was kinda of unexpected , but it’s alr now, thank you for your time

Solution:

num = {2,7,11,15}
target = 9

local idx = {}
for i, n in ipairs(num) do
    local j = idx[target - n]
    if j then
        print(j, i)
        break
    end
    idx[n] = i
end