I’ve been banging my head against the wall for a good 2hrs now trying to figure out why this isn’t working. I’m trying to get my server score board to display player’s online time. I already have a script that stores it in a database. Please have a look over the code and tell me if you spot any imeadate issues that would be causing this problem.

Client.lua

local nui = false
Citizen.CreateThread(function()
    local key = 27
    nui = false
    while true do
        Citizen.Wait(1)
        
        if IsControlPressed(0, key) then 
            if not nui then
                local players = {}
                ptable = GetPlayers()
                for _, i in ipairs(ptable) do
                    name = GetPlayerName(i)
                    TriggerServerEvent("scoreboard:getTime", name)
                    AddEventHandler("scoreboard:sendData", function(m, h, d) 
                    min = m
                    hrs = h
                    day = d
                    end)
                    table.insert(players,
                        '<tr style=\"color: #fff"><td>' .. GetPlayerServerId(i) .. '</td><td>' .. name .. '</td><td>'..day..'d '..hrs..'h '..min..'m</td></tr>')
                end

                SendNUIMessage({ text = table.concat(players) })

                nui = true
                while nui do
                    Wait(0)
                    if(IsControlPressed(0, key) == false) then
                        nui = false
                        SendNUIMessage({
                            meta = 'close'
                        })
                        break
                    end
                end
            end
        end
    end
end)

function GetPlayers()
    local players = {}
    for i = 0, 31 do
        if NetworkIsPlayerActive(i) then
            table.insert(players, i)
        end
    end
    return players
end

Server.lua

RegisterServerEvent("scoreboard:getTime")
AddEventHandler("scoreboard:getTime", function(name)
    MySQL.Async.fetchAll('SELECT * FROM times WHERE name=@name', {['@name'] = name}, function(timeData)
        if timeData[1] ~= nil then
            local m = timeData[1].Minutes
            local h = timeData[1].Hours
            local d = timeData[1].Days
            TriggerClientEvent("scoreboard:sendData",  m, h, d)
        end
	end)
end)

And could you actually let me know if this is even possible…

TriggerClientEvent’s first argument is an id or -1

so TriggerClientEvent("scoreboard:sendData", sourceid, m, h, d)

the players sourceid can be replaced with a -1 to send to all clients.

when you mean id, do you mean server id, playername, steam? because when i put a -1 it does nothing, no errors client side, or server side but it doesn’t work either.

Serverid

If it is not sending data at all with -1 then the IRS two options. There is an error overlooked or the server event is not being called.