• 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!

Solved Attempt to index local 'player' problem [TFS 1.2]

Joined
Jul 18, 2014
Messages
193
Solutions
2
Reaction score
15
Hi, i have this error when a globalevent executes:
antibot.lua:5:attempt to index local 'player' <a nil value>

And this is the script:
Code:
function onThink(cid, player, interval)

local player = Player(cid)

if player:getStorageValue(76965) < 1 then
    print("Bot inspection.")
    doPlayerSendTextMessage(cid, 22, "You have 3 minutes to say !antibot or you going to get kicked.")
    player:setStorageValue(76975, 1)
    player:setStorageValue(76976, os.time()+180)
    return true
end
if player:getStorageValue(76976) >= os.time() and player:getStorageValue(76975) == 1 then
    doRemoveCreature(cid)
end
return true
end

Sometimes i saw that someones puts:
If not player then
return true
end

But i tried this and nothing happens, and if i put return false instead return true, in console appears: Failed to execute event: antibot.

Please help!.
Thanks:)
 
Try this:

Code:
function onThink(interval)
    for _, player in ipairs(Game.getPlayers()) do
        if player:getStorageValue(76965) < 1 then
            print("Bot inspection.")
            player:sendTextMessage(22, "You have 3 minutes to say !antibot or you going to get kicked.")
            player:setStorageValue(76975, 1)
            player:setStorageValue(76976, os.time()+180)
        elseif player:getStorageValue(76976) >= os.time() and player:getStorageValue(76975) == 1 then
            player:remove()
        end
    end

    return true
end
 
If i were you i wouldn't even bother with this, improve ur script or people would just put so they would say !antibot every like 2.5 minutes
 
Try this:

Code:
function onThink(interval)
    for _, player in ipairs(Game.getPlayers()) do
        if player:getStorageValue(76965) < 1 then
            print("Bot inspection.")
            player:sendTextMessage(22, "You have 3 minutes to say !antibot or you going to get kicked.")
            player:setStorageValue(76975, 1)
            player:setStorageValue(76976, os.time()+180)
        elseif player:getStorageValue(76976) >= os.time() and player:getStorageValue(76975) == 1 then
            player:remove()
        end
    end

    return true
end
It works! Thanks!:D
 
Back
Top