Home > Blockchain >  How to fix this error: attempt to index a number value in Lua Script
How to fix this error: attempt to index a number value in Lua Script

Time:03-19

I'm learning Lua but I got this error attempt to index a number value when compiler reach this piece of code

if a() == -1 then
    return code
end

Console Error

1

i tried to change the type of return from number to boolean but i got the same error

Boolean console error

2

function a()
    local message = developer:historicalMessage(22)
    if message == nil or message[1] == nil then return nil end
    message = message[1]
    if message.subs == 0 then
        global:printMessage("Here !")
        return -1
    end
end

function Notif()
    if a() == -1 then
        return code
    end
end

CodePudding user response:

You haven't told us the line, but there are only a few indexing operations:

  • developer:historicalMessage(...) and global:printMessage(...) are presumably not the cause. If developer and global were numbers, they could be however. That seems unlikely to me as they are being used as "method tables" though (probably with metatables).
  • message.subs might be indexing the number message if developer:historicalMessage(22)[1] is a number.
  • Related