• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

TFS 1.X+ attempt to index a nil value

Fortera Global

Intermediate OT User
Joined
Nov 20, 2015
Messages
1,180
Solutions
2
Reaction score
117
why this error?
error:
Code:
Lua Script Error: [MoveEvents Interface]
data/movements/scripts/Meus/removerSummons.lua:onStepIn
data/movements/scripts/Meus/removerSummons.lua:11: attempt to index a nil value
stack traceback:
    [C]: in function '__index'
    data/movements/scripts/Meus/removerSummons.lua:11: in function <data/movements/scripts/Meus/removerSummons.lua:1>

code:
Lua:
function onStepIn(creature, item, position, fromPosition)
   
    if not creature then
        return false
    end
   
    if not creature:isMonster() then
        return false
    end   
   
    if not creature:getMaster():isPlayer() then
        return false
    end


tfs 1.x+
 
Solution
because getMaster() can return nil if the creature has no master, resulting in nil:getMaster() which is wrong
you need to check if master exists first before using it
Lua:
    local master = creature:getMaster()
    if master and not master:isPlayer() then
        return false
    end
because getMaster() can return nil if the creature has no master, resulting in nil:getMaster() which is wrong
you need to check if master exists first before using it
Lua:
    local master = creature:getMaster()
    if master and not master:isPlayer() then
        return false
    end
 
Solution
Back
Top