Jump to content

blip attach


Recommended Posts

Hi. Whats the problem?

debug error: line:10/attempt to index field '?' (nil value)
g_Root = getRootElement()
g_ResRoot = getResourceRootElement(getThisResource())
g_PlayerData = {}

function joinHandler(player)
    if not player then
        player = source
    end
    local r, g, b = math.random(50, 255), math.random(50, 255), math.random(50, 255)
    g_PlayerData[player].blip = createBlipAttachedTo(player, 0, 2, r, g, b) -- Line 10
end
addEventHandler('onPlayerJoin', g_Root, joinHandler)


addEventHandler('onResourceStart', g_ResRoot,
    function()
        joinHandler(player)
    end
)


function quitHandler(player)
    if type(player) ~= 'userdata' then
        player = source
    end
    if g_PlayerData[player].blip and isElement(g_PlayerData[player].blip) then
        destroyElement(g_PlayerData[player].blip)
    end
    g_PlayerData[player] = nil
end
addEventHandler('onPlayerQuit', g_Root, quitHandler)

addEventHandler('onResourceStop', g_ResRoot,
    function()
        for player,data in pairs(g_PlayerData) do
            quitHandler(player)
        end
    end
)

 

Link to comment

See the problem is that g_PlayerData[player] is not a table, you cannot use the '.key' property on it, since it hasn't been initialized yet. Add this before line 10 to make sure it is a table

g_PlayerData[player] = {}

 

Edited by pa3ck
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...