Help script car only for grade job

hello i try this and i go to spawn car and click “E” and dont apear menu

function OpenVehicleSpawnerMenu()

	local elements = {}

	if ESX.PlayerData.job.name == 'ambulance' and PlayerData.job.grade_name == 'inem0' then
		table.insert(elements, {label = _U('ambulance'), value = 'ambulance'})
	end
	if ESX.PlayerData.job.name == 'ambulance' and PlayerData.job.grade_name == 'inem1' then
		table.insert(elements, {label = _U('ambulance'), value = 'ambulance1'})
	end
	if ESX.PlayerData.job.name == 'ambulance' and PlayerData.job.grade_name == 'inem2' then
		table.insert(elements, {label = _U('ambulance'), value = 'ambulance'})
	end
	if ESX.PlayerData.job.name == 'ambulance' and PlayerData.job.grade_name == 'inem3' then
		table.insert(elements, {label = _U('ambulance'), value = 'ambulance'})
	end
	if ESX.PlayerData.job.name == 'ambulance' and PlayerData.job.grade_name == 'inem4' then
		table.insert(elements, {label = _U('ambulance'), value = 'ambulance'})
	end
	if ESX.PlayerData.job.name == 'ambulance' and PlayerData.job.grade_name == 'boss' then
		table.insert(elements, {label = _U('ambulance'), value = 'ambulance'})
	end
   
	ESX.UI.Menu.CloseAll()

	if Config.EnableSocietyOwnedVehicles then

		local elements = {}

		ESX.TriggerServerCallback('esx_society:getVehiclesInGarage', function(vehicles)
			for i=1, #vehicles, 1 do
				table.insert(elements, {
					label = GetDisplayNameFromVehicleModel(vehicles[i].model) .. ' [' .. vehicles[i].plate .. ']',
					value = vehicles[i]
				})
			end

			ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'vehicle_spawner',
			{
				title		= _U('veh_menu'),
				align		= 'top-left',
				elements = elements
			}, function(data, menu)
				menu.close()

				local vehicleProps = data.current.value
				ESX.Game.SpawnVehicle(vehicleProps.model, Config.Zones.VehicleSpawnPoint.Pos, 230.0, function(vehicle)
					ESX.Game.SetVehicleProperties(vehicle, vehicleProps)
					local playerPed = PlayerPedId()
					TaskWarpPedIntoVehicle(playerPed, vehicle, -1)
				end)
				TriggerServerEvent('esx_society:removeVehicleFromGarage', 'ambulance', vehicleProps)
			end, function(data, menu)
				menu.close()
				CurrentAction		= 'vehicle_spawner_menu'
				CurrentActionMsg	= _U('veh_spawn')
				CurrentActionData	= {}
			end)
		end, 'ambulance')

	else -- not society vehicles

		ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'vehicle_spawner',
		{
			title		= _U('veh_menu'),
			align		= 'top-left',
			elements	= elements,
        }, function(data, menu)
			menu.close()

			ESX.Game.SpawnVehicle(data.current.model, Config.Zones.VehicleSpawnPoint.Pos, 230.0, function(vehicle)
				local playerPed = PlayerPedId()
				TaskWarpPedIntoVehicle(playerPed, vehicle, -1)
			end)
		end, function(data, menu)
			menu.close()
			CurrentAction		= 'vehicle_spawner_menu'
			CurrentActionMsg	= _U('veh_spawn')
			CurrentActionData	= {}
		end)

	end
end

error on console f8:

line 450:

Citizen.CreateThread(function()
	while true do
		Citizen.Wait(10)

		if CurrentAction ~= nil then
			ESX.ShowHelpNotification(CurrentActionMsg)

			if IsControlJustReleased(0, Keys['E']) and ESX.PlayerData.job ~= nil and ESX.PlayerData.job.name == 'ambulance' then

				if CurrentAction == 'ambulance_actions_menu' then
					OpenAmbulanceActionsMenu()
				elseif CurrentAction == 'boss_actions_menu' then
					OpenBossActionsMenu()
				elseif CurrentAction == 'vehicle_spawner_menu' then
					OpenVehicleSpawnerMenu()
				elseif CurrentAction == 'pharmacy' then
					OpenPharmacyMenu()
--				elseif CurrentAction == 'fast_travel_goto_top' or CurrentAction == 'fast_travel_goto_bottom' then
--					FastTravel(CurrentActionData.pos)
				elseif CurrentAction == 'delete_vehicle' then
					if Config.EnableSocietyOwnedVehicles then
						local vehicleProps = ESX.Game.GetVehicleProperties(CurrentActionData.vehicle)
						TriggerServerEvent('esx_society:putVehicleInGarage', 'ambulance', vehicleProps)
					end
					ESX.Game.DeleteVehicle(CurrentActionData.vehicle)
				end

				CurrentAction = nil

			end

		end

		if IsControlJustReleased(0, Keys['F6']) and ESX.PlayerData.job ~= nil and ESX.PlayerData.job.name == 'ambulance' and not IsDead then
			OpenMobileAmbulanceActionsMenu()
		end
	end
end)

ANY help me?

Error seems to be at 611. Upload the file to pastebin or something like that, so we can refer to lines and read it better :wink:

line 611 is

if ESX.PlayerData.job.name == 'ambulance' and PlayerData.job.grade_name == 'inem0' then
		table.insert(elements, {label = _U('ambulance'), value = 'ambulance'})

Seems like PlayerData is returning nil. So it cant get it. I dont do much with ESX shit, so maybe thats a hint for you.

ty bro, i have another problem

how to remove paramedics and spawn ambulances? and police peds police cars and militar? how to remove all emergency?

Plent scripts for this in #development:releases just search

I use several but they are not working, only the cops disappear but the cars do not

First you say ESX.* then not. Shouldn’t it always be ESX.PlayerData.job.name?

1 Like