Function don't call ;(

Hello i try to use this code but my code isn’t called !

server :

require "resources/essentialmode/lib/MySQL"
MySQL:open("127.0.0.1", "gta5_gamemode_essential", "root", "ahhah")

local function genNum()
    local text = tostring(math.random(0, 99999999))
    while string.len(text) < 8 do
        text = "0"..text
    end
    return "0"..tostring(math.random(6,7))..text
end

local getNumber = function(ids)
    --get num
    local executed_query = MySQL:executeQuery("SELECT phone FROM users WHERE identifier = @identifier",{ ["@identifier"] = ids})
    local result = MySQL:getResults(executed_query, {'phone'}, "identifier")
    if not result[1] == nil then
        return tostring(result[1].phone)
    else
        while true do
            local num = genNum()
            local exMSQL = MySQL:excuteQuery("SELECT idetifier FROM users WHERE phone = @phone", { ["@phone"] = num})
            local resultSQL = MySQL:getResults(exMSQL, {'indentifier'}, "phone")
            if resultSQL[1] == nil then
                local exSave = MySQL:excuteQuery("UPDATE users SET phone = @phone WHERE identifier = "..ids, { ["@phone"] = num})
                return num
            end
        end
    end
    return "666"
end

AddEventHandler("playerSpawned", function(spawn)
    local player = source
    TriggerEvent('es:getPlayerFromId', player, function(user)
        TriggerClientEvent("phone:init", player , getNumber(user.identifier))
    end)
end)
 

Thank’s you !

is there a RegisterNetEvent for phone:init? is there anything in the server console about it not being whitelisted?

I’ve also never seen AddEventHandler(“playerSpawned”, function(spawn) called like that in a server script. I found 20 matches of that line, all in client scripts. Pretty sure you can’t make a wrapper like that of a client event in a server script.

fivem loadouts does this

AddEventHandler(“playerSpawned”, function(spawn)
TriggerServerEvent(“loadout:playerSpawned”, spawn)
end)

I assume his code works, and yours doesn’t, so I’d probably do it like this. :stuck_out_tongue:

Why did i have this error ?

This is the script :

AddEventHandler('es:playerLoaded', function(source)
  TriggerEvent('es:getPlayerFromId', source, function(user)
  local player = user.identifier
  print(player .." <------------ C'est le player") --- STEAM ID !
  print(source .." <------------ C'est la source") --- ID In game !
  TriggerClientEvent("phone:init", user.identifier , getNumber(user.identifier))
  end)
end)

You should be calling TriggerClientEvent on source and not the identifier.

I fixed this but i had a new error ;( :

--Version 1.3
require "resources/essentialmode/lib/MySQL"
--Configuration de la connexion vers la DB MySQL
MySQL:open("127.0.0.1", "gta5_gamemode_essential", "root", "ahahahah")

local function genNum()
    local text = tostring(math.random(0, 99999999))
    while string.len(text) < 8 do
        text = "0"..text
    end
    return "0"..tostring(math.random(6,7))..text
end

local getNumber = function(ids)
    --get num
    local executed_query = MySQL:executeQuery("SELECT phone_number FROM users WHERE identifier = '@identifier'",{ ["@identifier"] = ids})
    local result = MySQL:getResults(executed_query, {'phone_number'}, "identifier")
    if not result[1] == nil then
        return tostring(result[1].phone_number)
    else
        while true do
            local num = genNum()
            local exMSQL = MySQL:excuteQuery("SELECT identifier FROM users WHERE phone_number = '@phone'", { ["@phone"] = num})
            local resultSQL = MySQL:getResults(exMSQL, {'identifier'}, "phone_number")
            if resultSQL[1] == nil then
                local exSave = MySQL:excuteQuery("UPDATE users SET phone_number = '@phone' WHERE identifier = '' ..ids.. ''", { ["@phone"] = num})
                return num
            end
        end
    end
    return "666"
end

--[[AddEventHandler("playerSpawned", function(spawn)
    local player = spawn
    TriggerEvent('es:getPlayerFromId', player, function(user)
        TriggerClientEvent("phone:init", player , getNumber(user.identifier))
    end)
end) --]]

AddEventHandler('es:playerLoaded', function(source)
  TriggerEvent('es:getPlayerFromId', source, function(user)
  local player = user.identifier
  print(player .." <------------ C'est le player") --- STEAM ID !
  print(source .." <------------ C'est la source") --- ID In game !
  TriggerClientEvent("phone:init", source, getNumber(user.identifier))
  end)
end)



You just made a typo, you writed excuteQuery mutlitple times, it should be executeQuery (Missing one ‘e’)

Yes <3 thank’s you so much !