ESX attempt to call a value (field 'GetPlayerFromId' error

hy guys! i create server and failed mission -x money remove omething is not right. I need help thank you have nice day! F8 error:

Code:

		 gametime = GetGameTimer()
    seconds = 15 -- max time (seconds) you want to set
    printtime = seconds
   Citizen.CreateThread(function()
       while van do
           Citizen.Wait(0)
          if printtime > 0 then
               diftime = GetGameTimer() - gametime
               printtime = math.floor(seconds - (diftime/1000))
			   if printtime >= 10 then
               drawTxt(" ")
			   else
			   local xPlayer = ESX.GetPlayerFromId(source)
			      xPlayer.removeMoney(1000)
				  drawTxt("SZÁLLJ VISSZA  A KAMINODBA! Még van: " .. printtime .. " másodperced! különben levonunk: ~r~-1000$")
              end
			 
              else
              

Which one is line 97? and most likely it’s only a typo, GetPlayerFromFId whereas it should be GetPlayerFromId

1 Like

As Pigro stated, this indeed is high likely a typo in your GetPlayerFromId call.

As the error says, navigate to your client.lua and check if you made any typo’s on line 97.

1 Like

yes and change,
keeps deducting - money and disconnect server one error:
’ Reliable network event overflow ’
Code:
client.lua

	 gametime = GetGameTimer()
    seconds = 15 -- max time (seconds) you want to set
    printtime = seconds
   Citizen.CreateThread(function()
       while van do
           Citizen.Wait(0)
          if printtime > 0 then
               diftime = GetGameTimer() - gametime
               printtime = math.floor(seconds - (diftime/1000))
			   if printtime >= 10 then
               drawTxt(" ")
			   else
			 
			  
				  drawTxt("SZÁLLJ VISSZA  A KAMINODBA! Még van: " .. printtime .. " másodperced! különben levonunk: ~r~-1000$")
              end
			 
              else
              
          
								
			 
			
            TriggerServerEvent('esx_ets:PayBill60Zone')
		
			   
			   
			   RemoveBlip(truckBlip)
			    DeleteVehicle(trailer)
    RemoveBlip(destinationBlip)
    RemoveBlip(trailerBlip)
 
	 DeleteVehicle(truck)
	
	working = false
			      
			   
				  
		
       
	  
	  end
end
   end)

server. lua

RegisterServerEvent('esx_ets:PayBill60Zone')
AddEventHandler('esx_ets:PayBill60Zone', function()
	local xPlayer = ESX.GetPlayerFromId(source)
	
	xPlayer.removeMoney(100)
end)

Thank you helping how to fix?

So the getplayerfromid has been fixed? Well your money keeps getting deducted because you just coded the payment in a while loop, and Triggering server event should not be spammed. It will cause just that, reliable event network overflow.

yes how to fix?

First, fix your loop. Second, Idk what you are trying to achieve here, you need to be detailed. Not just how to fix and not all people will fix your code completely, we may just tell you the logic on what to do. So please, be detailed.

how to fix loop?

:man_facepalming:t2:
Bro, please read my second point

i want to remove player money if they dont make the delivery.
How can i do that? What are the code for that?

client.lua

ESX = nil


local PlayerData, startBlip, working = {}, nil, false

RegisterNetEvent('esx:playerLoaded')
AddEventHandler('esx:playerLoaded', function(playerId,xPlayer)
    PlayerData = xPlayer   
end)

RegisterNetEvent('esx:setJob')
AddEventHandler('esx:setJob', function(job)
    PlayerData.job = job
end)

Citizen.CreateThread(function()
    while ESX == nil do TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end) Wait(0) end
    while ESX.GetPlayerData().job == nil do Wait(0) end
    PlayerData = ESX.GetPlayerData()
    while true do
        local me, sleep, hasjob = PlayerPedId(), 250, true
        if Config.Job['jobRequired'] then
            if PlayerData.job.name ~= Config.Job['jobName'] then
                hasjob = false
            end
        end
        if working then hasjob = false end
        if hasjob then
            if not DoesBlipExist(startBlip) then
                startBlip = addBlip(Config.JobCenter, 632, 44, Strings['start_job'])
            end
        else
            if DoesBlipExist(startBlip) then
                RemoveBlip(startBlip)
            end
        end
        local distance = GetDistanceBetweenCoords(GetEntityCoords(me), Config.JobCenter, true)
        if distance <= 25.0 and hasjob then
            sleep = 0
            DrawMarker(39, Config.JobCenter, vector3(0.0, 0.0, 0.0), vector3(0.0, 0.0, 0.0), vector3(1.0, 1.0, 1.0), 255, 100, 0, 150, false, false, 2, false, false, false)
            if distance <= 1.5 then
                helpText(Strings['e_browse_jobs'])
                if IsControlJustReleased(0, 38) then
                    TriggerServerEvent('esx_ets:jobMenu')
                end
            end
        end
        Wait(sleep)
    end
end)
local van = true
RegisterNetEvent('esx_ets:start')
AddEventHandler('esx_ets:start', function(data, jobid)


  





    working = true
    local truck, trailer = loadVehicle(data.vehicles[1], data.start[1], data.start[2]), loadVehicle(data.vehicles[2], data.trailer[1], data.trailer[2])
    local destinationBlip, truckBlip, trailerBlip = addBlip(data.arrive, 38, 3, Strings['destination'])
    while true do
	        
        local sleep, distance = 250, GetDistanceBetweenCoords(data.arrive, GetEntityCoords(trailer), true)
	if not IsPedInVehicle(PlayerPedId(), truck, false) then
		
		
	    
	
	
            text(Strings['get_to_truck'], 250)
            if not DoesBlipExist(truckBlip) then
		     	
                truckBlip = addBlip(GetEntityCoords(truck), 477, 5, Strings['truck']) 
                SetBlipRoute(truckBlip, true) 
            end
			
				van =true
				 
            if DoesBlipExist(trailerBlip) then RemoveBlip(trailerBlip) end
            if DoesBlipExist(destinationBlip) then RemoveBlip(destinationBlip) end
        else
		
		 gametime = GetGameTimer()
    seconds = 15 -- max time (seconds) you want to set
    printtime = seconds
   Citizen.CreateThread(function()
       while van do
           Citizen.Wait(0)
          if printtime > 0 then
               diftime = GetGameTimer() - gametime
               printtime = math.floor(seconds - (diftime/1000))
			   if printtime >= 10 then
               drawTxt(" ")
			   else
			 
			  
				  drawTxt("SZÁLLJ VISSZA  A KAMINODBA! Még van: " .. printtime .. " másodperced! különben levonunk: ~r~-1000$")
              end
			 
              else
              
          
								
			 
			
            
		
			   
			   
			   RemoveBlip(truckBlip)
			    DeleteVehicle(trailer)
    RemoveBlip(destinationBlip)
    RemoveBlip(trailerBlip)
 
	 DeleteVehicle(truck)
	
	working = false
            	
			    
			   TriggerServerEvent('esx_ets:PayBill60Zone');
				  
		
       
	  
	  end
end
   end)
            if not IsVehicleAttachedToTrailer(truck, trailer) then
			  
                text(Strings['get_to_trailer'], 250)
				
                if not DoesBlipExist(trailerBlip) then 
                    trailerBlip = addBlip(GetEntityCoords(trailer), 479, 5, Strings['trailer']) 
                    SetBlipRoute(trailerBlip, true) 
                end
                if DoesBlipExist(destinationBlip) then RemoveBlip(destinationBlip) end
            else
                if DoesBlipExist(trailerBlip) then RemoveBlip(trailerBlip) end

                if not DoesBlipExist(destinationBlip) then
                    destinationBlip = addBlip(data.arrive, 38, 3, Strings['destination'])
                    SetBlipRoute(destinationBlip, true)
                end
            end
            if DoesBlipExist(truckBlip) then RemoveBlip(truckBlip) end
        end
        if distance <= 45.0 and IsPedInVehicle(PlayerPedId(), truck, false) and IsVehicleAttachedToTrailer(truck, trailer) then
            sleep = 0
            DrawMarker(1, data.arrive, vector3(0.0, 0.0, 0.0), vector3(0.0, 0.0, 0.0), vector3(1.0, 1.0, 1.0), 255, 255, 50, 150, false, false, 2, false, false, false)
            if distance <= 10.0 then
                while IsVehicleAttachedToTrailer(truck, trailer) do 
                    text(Strings['detach'], 250)
                    Wait(250)
                end
                break
            else
                text(Strings['park'])
            end
        else
            if IsPedInVehicle(PlayerPedId(), truck, false) and IsVehicleAttachedToTrailer(truck, trailer) then
                text(Strings['drive_destination'], 250)
            end
        end
        Wait(sleep)
    end
    DeleteVehicle(trailer)
    RemoveBlip(destinationBlip)
    RemoveBlip(trailerBlip)
    RemoveBlip(truckBlip)
	  TriggerServerEvent('esx_ets:jobFinished', jobid, damages)
    while true do
	
	
        local sleep, distance = 250, GetDistanceBetweenCoords(GetEntityCoords(truck), data.start[1], true)
        if not IsPedInVehicle(PlayerPedId(), truck, false) and distance >= 10.0 then
		
		   
		
				  
	
	
		
            text(Strings['get_to_truck'], 250)
			van=true
	    
            if not DoesBlipExist(truckBlip) then
	
			   
                truckBlip = addBlip(GetEntityCoords(truck), 477, 5, Strings['truck']) 
                SetBlipRoute(truckBlip, true) 
				
            end
			van=true
            if DoesBlipExist(destinationBlip) then RemoveBlip(destinationBlip) end
        else
		
			       	 gametime = GetGameTimer()
    seconds = 65 -- max time (seconds) you want to set
    printtime = seconds
   Citizen.CreateThread(function()
       while van do
           Citizen.Wait(0)
		   
          if printtime > 0 then
               diftime = GetGameTimer() - gametime
               printtime = math.floor(seconds - (diftime/1000))
			   if printtime >= 60 then
               drawTxt(" ")
			   else
				  drawTxt("SZÁLLJ VISSZA  A KAMINODBA! Még van: " .. printtime .. " másodperced! különben levonunk: ~r~-1000$")
             end
              else
              
			   
			     
			   
              DeleteVehicle(trailer)
    RemoveBlip(destinationBlip)
    RemoveBlip(trailerBlip)
    RemoveBlip(truckBlip)
	 DeleteVehicle(truck)
	
	working = false
	 text(Strings['failed'])
	 
			    
         end
       end
	   
   end)
           
		
            if DoesBlipExist(truckBlip) then RemoveBlip(truckBlip) end
			
	
			
			
			
            if not DoesBlipExist(destinationBlip) then
                destinationBlip = addBlip(data.start[1], 38, 3, Strings['destination'])
                SetBlipRoute(destinationBlip, true)
            end
            if distance <= 30.0 then
                sleep = 0
                DrawMarker(1, data.start[1], vector3(0.0, 0.0, 0.0), vector3(0.0, 0.0, 0.0), vector3(1.0, 1.0, 1.0), 255, 255, 50, 150, false, false, 2, false, false, false)
                if distance <= 10.0 then
                    if IsPedInVehicle(PlayerPedId(), truck, false) then
                        text(Strings['get_out'])
                    else
                        if DoesBlipExist(destinationBlip) then RemoveBlip(destinationBlip) end
                        if DoesBlipExist(truckBlip) then RemoveBlip(truckBlip) end
										   
		
                        break
                    end
                else
                    text(Strings['park_truck'])
                end
            else
                text(Strings['drive_back'], 250)
            end
        end
		
        Wait(sleep)
    end
    local damages = {['windows'] = {}, ['tires'] = {}, ['doors'] = {}, ['body_health'] = GetVehicleBodyHealth(truck), ['engine_health'] = GetVehicleEngineHealth(truck)}
    for i = 0, GetVehicleNumberOfWheels(truck) do
        if IsVehicleTyreBurst(truck, i, false) then table.insert(damages['tires'], i) end 
    end
    for i = 0, 13 do
        if not IsVehicleWindowIntact(truck, i) then table.insert(damages['windows'], i) end
    end
    for i = 0, GetNumberOfVehicleDoors(truck) do 
        if IsVehicleDoorDamaged(truck, i) then table.insert(damages['doors'], i) end 
    end
	van =false
    DeleteVehicle(truck)
    working = false
    TriggerServerEvent('esx_ets:jobFinished', jobid, damages)
end)

RegisterNetEvent('esx_ets:menu')
AddEventHandler('esx_ets:menu', function(data)
    ESX.UI.Menu.CloseAll()
    ESX.UI.Menu.Open(
            'default', GetCurrentResourceName(), 'choose_job',
        {
            title = Strings['menu_title'],
            align = 'center',
            elements = data
        },
        function(data, menu)
            TriggerServerEvent('esx_ets:startJob', data.current.value)
            menu.close()
        end,
    function(data, menu)
        menu.close()
    end)
end)

text = function(text, duration)
    ClearPrints()
    BeginTextCommandPrint('STRING')
    AddTextComponentSubstringPlayerName(text)
    EndTextCommandPrint(duration, 2)
end


loadVehicle = function(vehicle, coords, heading)
    local model
    if type(vehicle) == 'number' then model = vehicle else model = GetHashKey(vehicle) end
    while not HasModelLoaded(model) do Wait(0) RequestModel(model) end
    local car = CreateVehicle(model, coords, heading, true, false)
    SetEntityAsMissionEntity(car, true, true)
    return car
end

helpText = function(msg)
    BeginTextCommandDisplayHelp('STRING')
    AddTextComponentSubstringPlayerName(msg)
    EndTextCommandDisplayHelp(0, false, true, 1)
end

addBlip = function(coords, sprite, colour, text)
    local blip = AddBlipForCoord(coords)
    SetBlipSprite(blip, sprite)
    SetBlipColour(blip, colour)
    SetBlipAsShortRange(blip, true)
    BeginTextCommandSetBlipName("STRING")
    AddTextComponentString(text)
    EndTextCommandSetBlipName(blip)
    return blip
end

function drawTxt(content)
    SetTextFont(4)
    SetTextScale(0.6, 0.6)
    SetTextColour(255,255,255, 255)
    SetTextEntry("STRING")
    SetTextDropShadow(0, 0, 0, 0,255)
    SetTextDropShadow()
    SetTextEdge(4, 0, 0, 0, 255)
    SetTextOutline()
    AddTextComponentString(content)
    DrawText(0.17,0.02 )
end

server.lua

ESX = nil
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)

for k, v in pairs(Config.Jobs) do
    v['taken'] = false
end

RegisterServerEvent('esx_ets:startJob')
AddEventHandler('esx_ets:startJob', function(id)
    local xPlayer, hasJob = ESX.GetPlayerFromId(source), true
    if Config.Job['jobRequired'] then
        if xPlayer.job.name == Config.Job['jobName'] then
            hasJob = true
        else
            hasJob = false
        end
    end
    if hasJob then
        if not Config.Jobs[id]['taken'] then
            Config.Jobs[id]['taken'] = true
            TriggerClientEvent('esx_ets:start', xPlayer.source, Config.Jobs[id], id)
        else
            TriggerClientEvent('esx:showNotification', xPlayer.source, Strings['somebody_doing'])
        end
    else
        TriggerClientEvent('esx:showNotification', xPlayer.source, Strings['not_job'])
    end
end)

RegisterServerEvent('esx_ets:jobMenu')
AddEventHandler('esx_ets:jobMenu', function()
    local elements, xPlayer = {}, ESX.GetPlayerFromId(source)
    for k, v in pairs(Config.Jobs) do
        if not v['taken'] then
            table.insert(elements, {label = v.title, value = k})
        end
    end
    TriggerClientEvent('esx_ets:menu', xPlayer.source, elements)
end)

RegisterServerEvent('esx_ets:jobFinished')
AddEventHandler('esx_ets:jobFinished', function(id, damages)
    local xPlayer = ESX.GetPlayerFromId(source)
    if Config.Jobs[id]['taken'] then
        local price, health = Config.Jobs[id].payment, (damages['body_health'] + damages['engine_health']) / 2
        for k, v in pairs(damages['windows']) do health = health - 30 end
        for k, v in pairs(damages['tires']) do health = health - 35 end
        for k, v in pairs(damages['doors']) do health = health - 40 end
        if health <= 900 and health > 800 then price = price - 50 elseif health <= 800 and health > 700 then price = price - 75 elseif health <= 700 and health > 600 then price = price - 100 elseif health <= 600 and health > 300 then price = price - 150 elseif health <= 300 then price = price - 350 end
        if price >= 0 then
            xPlayer.addMoney(price)
            TriggerClientEvent('esx:showNotification', xPlayer.source, (Strings['reward']):format(price))
        else
            xPlayer.removeMoney(price)
            TriggerClientEvent('esx:showNotification', xPlayer.source, (Strings['paid_damages']):format(price))
        end
        Wait(Config.ReAdd * 1000)
        Config.Jobs[id]['taken'] = false
    end
end)


RegisterServerEvent('esx_ets:PayBill60Zone')
AddEventHandler('esx_ets:PayBill60Zone', function()
	local xPlayer = ESX.GetPlayerFromId(source)
	
	xPlayer.removeMoney(100)
	
end)

First i would add local fail = false after esx_ets start
then when they fail because printtime is 0 add fail = true
lastly add this code to the last part of esx_ets start eventhandler

		
        Wait(sleep)
    end
    if fail then
        TriggerServerEvent('esx_ets:PayBill60Zone');
    end
    local damages = {['windows'] = {}, ['tires'] = {}, ['doors'] = {}, ['body_health'] = GetVehicleBodyHealth(truck), ['engine_health'] = GetVehicleEngineHealth(truck)}
    for i = 0, GetVehicleNumberOfWheels(truck) do
        if IsVehicleTyreBurst(truck, i, false) then table.insert(damages['tires'], i) end 
    end```

sorry i send wrong file because the file dont have game timer script, so printtimer not in the file.
because this script caused “resource time warning” .server lagging, and fps drop
so default files
client.lua (8.4 KB) server.lua (2.5 KB)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.