[HELP] AI Bus

Hello, I’m trying to make a resource in which a bus around a direction that I put everything goes well except a couple of things, like when someone shoots near the truck the pilot goes crazy, the other thing is that i cant get in the bus when i press the key “E” dont happens nothing and and i have an error in line 34

i have this in client client.lua (1.7 KB)

local vehicles = {“bus”}
local hash = GetHashKey(vehicles[math.random(#vehicles)])

–BUS
Citizen.CreateThread(function()
local piloto = “s_m_m_pilot_01”
local modelHash = GetHashKey(piloto)
RequestModel(hash)
RequestModel(modelHash)
local bus = CreateVehicle(hash, 251.89724731446,-577.37591552734,43.293083190918, 160.0, true, true)
globalbus = bus
SetEntityAsMissionEntity(globalbus, true, true)
local pilot = CreatePedInsideVehicle(bus, 1, modelHash, -1, true, true)
SetPedSeeingRange(pilot, false)
SetPedHearingRange(pilot, false)
SetPedPathAvoidFire(pilot, false)
SetPedCombatMovement(pilot, 0)
TaskVehicleDriveToCoord(pilot, bus, 251.89724731446,-577.37591552734,43.293083190918, 17.0, 0, vehiclehash, 387, 1.0, true)
parada = true
Citizen.Wait(10000)
parada = false
TaskVehicleDriveToCoord(pilot, bus, 171.0301208496,-788.73962402344,31.385557174682, 17.0, 0, vehiclehash, 387, 1.0, true)
parada = true
Citizen.Wait(10000)
parada = false
end)

–distance
Citizen.CreateThread(function()
local playerPed = GetPlayerPed(-1)
busCoords = GetEntityCoords(pilot)
myCoords = GetEntityCoords(playerPed)
–local busdistance = GetDistanceBetweenCoords(myCoords.x, myCoords.y, myCoords.z, busCoords.x,busCoords.y,busCoords.z,true)
end)

–get on bus
Citizen.CreateThread(function()
local playerPed = GetPlayerPed(-1)
while true do
Citizen.Wait(0)
if parada == true then
–if busdistance < 20 then
if IsControlJustReleased(0, 38) then
TaskEnterVehicle(GetPlayerPed(-1), globalbus, 1000, 0, 2.0, 1, 0)
–TaskWarpPedIntoVehicle(playerPed, bus, math.random(0,2))

  		 end
  	  --end
      end
  end

end
end)

Thats a great idea.

Opa, se você ainda precisa de ajuda nisso.
Para fazer com que o ped não se assute com tiros ou o que está acontecendo ao seu redor você deve definir:
TaskSetBlockingOfNonTemporaryEvents(ped, true)
Dai você define o evento de dirigir e depois disso:
TaskSetBlockingOfNonTemporaryEvents(ped, true)

If you are still working on it…

You have not set globalbus to the bus, that are driving around.