Jump to content

[Problem] 'end' expected near 'break'


Bilal135

Recommended Posts

So I have a table called joinedPlayers and it looks something like this,

joinedPlayers = { [key] = {source, posX, posY, posZ} } -- 'key' is generated automatically

I inserted into the table in this way,

local x, y, z = getElementPosition(source)
table.insert(joinedPlayers, {source, x, y, z})

I was trying to find the key of a certain player but kept getting this error - 'end' expected near 'break'.

function findPlayerKey(player)
  for k, v in pairs(joinedPlayers) do
    if v[1] == player then
      return k
      break
    else
      return false
    end
  end
end

 

Link to comment
  • Moderators

Because you leave from function with return before break.

 

function findPlayerKey(player)
    for k, v in pairs(joinedPlayers) do
        if v[1] == player then
            return k -- return key if player found
        end
    end
    return false -- return false at and of the function if player not found
end

 

Edited by stPatrick
  • Thanks 1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...