esx-community / esx_scoreboard

An fork of Stadus_Scoreboard with major improvements
MIT License
21 stars 49 forks source link

attempt to index a nil value (local 'xPlayer') #13

Closed HalCroves closed 5 years ago

HalCroves commented 5 years ago

Hi, Thank you for all the resources you are updating!

Since your last upload, at the start of the addon, I get the error message "attempt to index a nil value (local 'xPlayer') at line 44".

For me the line 44 is : local playerId = xPlayer.source

function AddPlayerToScoreboard(xPlayer, update)
    local playerId = xPlayer.source

    connectedPlayers[playerId] = {}
    connectedPlayers[playerId].ping = GetPlayerPing(playerId)
    connectedPlayers[playerId].id = playerId
    connectedPlayers[playerId].name = xPlayer.getName()
    connectedPlayers[playerId].job = xPlayer.job.name

    if update then
        TriggerClientEvent('esx_scoreboard:updateConnectedPlayers', -1, connectedPlayers)
    end

    if xPlayer.player.getGroup() == 'user' then
        Citizen.CreateThread(function()
            Citizen.Wait(3000)
            TriggerClientEvent('esx_scoreboard:toggleID', playerId, false)
        end)
    end
end

I can not understand why he can not retrieve information from "xPlayer" derived from AddEventHandler('esx:playerLoaded', function(playerId, xPlayer).

But when I restart the addon, it retrieves the information.

For the moment, i have replace the function :

AddEventHandler('esx:playerLoaded', function(playerId, xPlayer)
    AddPlayerToScoreboard(xPlayer, true)
end)

By :

AddEventHandler('esx:playerLoaded', function(playerId, xPlayer)
    local players = ESX.GetPlayers()

    for i=1, #players, 1 do
        local xPlayer = ESX.GetPlayerFromId(players[i])
        AddPlayerToScoreboard(xPlayer, false)
    end
end)

But I think it's a lousy method

Do you have an idea on this?

Thanks on advance.

Cordially, Hal

ElPumpo commented 5 years ago

Update esx

codibez commented 5 years ago

@ElPumpo @HalCroves What did you do to solve this. I am also getting this issue and I have the latest version of esx.

Dinamicka commented 5 years ago

i already have the lastest version of esx an i have the same error

Error running system event handling function for resource esx_scoreboard: citizen:/scripting/lua/scheduler.lua:41: Failed to execute thread: server/main.lua:43: attempt to index a nil value (local 'xPlayer') stack traceback: server/main.lua:43: in function 'AddPlayerToScoreboard' server/main.lua:17: in upvalue 'handler' citizen:/scripting/lua/scheduler.lua:219: in function <citizen:/scripting/lua/scheduler.lua:218> stack traceback: [C]: in function 'error' citizen:/scripting/lua/scheduler.lua:41: in field 'CreateThreadNow' citizen:/scripting/lua/scheduler.lua:218: in function <citizen:/scripting/lua/scheduler.lua:182>

doteric commented 5 years ago

Replace

AddEventHandler('esx:playerLoaded', function(playerId, xPlayer)
    AddPlayerToScoreboard(xPlayer, true)
end)

with

AddEventHandler('esx:playerLoaded', function(xPlayer)
    AddPlayerToScoreboard(xPlayer, true)
end)

and remove .source from AddPlayerToScoreboard like local playerId = xPlayer

Redrock69 commented 4 years ago

Where can I replace the default icons?

nessx commented 4 years ago

Yes in -> esx_scoreboard/html/scoreboard.html at the line 14 to 19.

         `<div class="header">
        <div class="jobs">
            <p style="color:red;"> 👨‍⚕️ <span id="ems">0</span> </p>
            <p style="color:#5ea1e0;"> 👮🏻 <span id="police">0</span> </p>
            <p style="color:yellow;"> 🚕 <span id="taxi">0</span> </p>
            <p style="color:grey;"> 🔧 <span id="mechanic">0</span> </p>
            <p style="color:lightblue;"> 🚗 <span id="cardealer">0</span> </p>
            <p style="color:#58ce93;"> 🏘️ <span id="estate">0</span> </p>
        </div>
    </div>`
monyroath commented 4 years ago

can u guys help me how to change steam name to Indetity name in the game

stjdetr commented 3 years ago

So thank you bro

KralqNaOrkite commented 1 year ago

i have some other problem again with this script

SCRIPT ERROR: @esx_scoreboard/server/main.lua:54: attempt to index a nil value (field 'player') that is what it says in the console

if xPlayer.player.getGroup() == 'user' then Citizen.CreateThread(function() Citizen.Wait(3000) TriggerClientEvent('esx_scoreboard:toggleID', playerId, false) end) end end this is the comand that is wrong pls someone help