Jump to content

Number with Nil


Controlled

Recommended Posts

    local gameAccountID = getElementData(thePlayer, "account:id") 
    local dbid = getElementData(thePlayer, "dbid") 
    mResult2 = exports.mysql:query_fetch_assoc("SELECT `vp` FROM `accounts` WHERE `id`='".. tostring(gameAccountID) .."'") 
    Stats = tonumber(mResult2["vp"]) 
    elseif (Stats>0) then 
        setPlayerNametagColor(thePlayer, 167, 133, 63) 

Error is Number with Nil on elseif line. How can 0 be Nil? lol

I tried writing it like

Stats > 0

Stats>0

(Stats > 0)

(Stats>0)

All the same lol

Link to comment
    local gameAccountID = getElementData(thePlayer, "account:id") 
    local dbid = getElementData(thePlayer, "dbid") 
    mResult2 = exports.mysql:query_fetch_assoc("SELECT `vp` FROM `accounts` WHERE `id`='".. tostring(gameAccountID) .."'") 
    if (mResult2) then 
        Stats = tonumber(mResult2[1]["vp"]) 
        if (Stats>0) then 
            setPlayerNametagColor(thePlayer, 167, 133, 63) 
        end 
    end 

Link to comment

And I thought that at first too, so I made this.

function old( thePlayer ) 
if thePlayer then 
        local logged = getElementData(thePlayer, "loggedin") 
        if (logged==1) then 
    local gameAccountID = getElementData(thePlayer, "account:id") 
    local dbid = getElementData(thePlayer, "dbid") 
    mResult2 = exports.mysql:query_fetch_assoc("SELECT `vp` FROM `accounts` WHERE `id`='".. tostring(gameAccountID) .."'") 
    Stats = tonumber(mResult2["vp"]) 
    if (Stats>0) then 
    outputChatBox("You have", thePlayer) 
    else  
    outputChatBox("You don't", thePlayer) 
    end 
    end 
    end 
    end 
addCommandHandler("checkVP", old) 

It worked fine without errors.

Link to comment
    local gameAccountID = getElementData(thePlayer, "account:id") 
    local dbid = getElementData(thePlayer, "dbid") 
    mResult2 = exports.mysql:query_fetch_assoc("SELECT `vp` FROM `accounts` WHERE `id`='".. tostring(gameAccountID) .."'") 
    if (mResult2) then 
        Stats = tonumber(mResult2[1]["vp"]) 
        if (Stats>0) then 
            setPlayerNametagColor(thePlayer, 167, 133, 63) 
        end 
    end 

Returns the Error, Attempt to Index Field "?" (A Nil Value)

on Stats = tonumber(mResult2[1]["vp"]

Link to comment
function old( thePlayer ) 
    if thePlayer then 
        local logged = getElementData(thePlayer, "loggedin") 
        if (logged==1) then 
            local gameAccountID = getElementData(thePlayer, "account:id") 
            local dbid = getElementData(thePlayer, "dbid") 
            mResult2 = exports.mysql:query_fetch_assoc("SELECT `vp` FROM `accounts` WHERE `id`='".. tostring(gameAccountID) .."'") 
            if (mResult2 and mResult2[1]["vp"]) then 
                Stats = tonumber(mResult2[1]["vp"]) 
                if (Stats>0) then 
                    outputChatBox("You have", thePlayer) 
                else 
                    outputChatBox("You don't", thePlayer) 
                end 
            end 
        end 
    end 
end 
addCommandHandler("checkVP", old) 

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...