attempt to index a nil value

Discussion in 'Support' started by God Of Pain, Apr 16, 2018.

  1. God Of Pain

    God Of Pain Member

    Joined:
    Aug 3, 2017
    Messages:
    471
    Likes Received:
    12
    Best Answers:
    8
    Help? why this?

    error:
    Code (Text):
    1. Lua Script Error: [Monster Interface]
    2. data/monster/scripts/newSummon.lua:onThink
    3. data/monster/scripts/newSummon.lua:3: attempt to index a nil value
    4. stack traceback:
    5.     [C]: in function '__index'
    6.     data/monster/scripts/newSummon.lua:3: in function <data/monster/scripts/newSummon.lua:1>
    script:
    Code (Lua):
    1. function onThink(self, interval)
    2.     if self:isMonster() then
    3.         if self:getMaster():isPlayer() then
    4.             local creatureId = self:getId()
    5.             local player = self:getMaster()
    6.          
    7.                if not SummonRegenEvents[creatureId] then
    8.                 SummonRegenEvents[creatureId] = addEvent(doRegenSummon, SummonRegenEvents.config.interval * 1000, creatureId)
    9.             end
    10.         end
    11.     end
    12. end
    tfs 1 2
     
  2. Best Answer:
    Post #4 by Nekiro, Apr 16, 2018
  3. Nekiro

    Nekiro worst coder Support Team

    Joined:
    Sep 7, 2015
    Messages:
    1,695
    Likes Received:
    522
    Best Answers:
    69
    self:getMaster() returned nil value, because self has no master.
     
  4. God Of Pain

    God Of Pain Member

    Joined:
    Aug 3, 2017
    Messages:
    471
    Likes Received:
    12
    Best Answers:
    8
    Then I need to check:

    Code (Lua):
    1. if self:getMaster() then
    2. if self:getMaster():isPlayer() then
    right?
     
  5. Nekiro

    Nekiro worst coder Support Team

    Joined:
    Sep 7, 2015
    Messages:
    1,695
    Likes Received:
    522
    Best Answers:
    69
    Best Answer
    Code (Text):
    1. local master = self:getMaster()
    2. if master and master:isPlayer() then
     

Share This Page

Loading...