Tryna get this code to work

i am trying to make this code to trigger when i enter the vehicle. But it instead triggers when i start the mission. And it does not seem to check if i am in that vehicle. Does anyone know if i have done something wrong with this code?

image

Gotta do it in a while loop to check when youre in the vehicle. Use a break statement to exit the thread.

Citizen.CreateThread(function()
   while true do
      Citizen.Wait(500)
      // your code here ....
   end
end)

Better yet, look into this. I believe there’s an event that triggers when you enter a vehicle, the upside to this is better script performance.
https://docs.fivem.net/docs/scripting-reference/events/list/gameEventTriggered/

i checked it out but i could not find an event that triggers when player is entering the vehicle. I only find when a ped is entering

also i tried to do this code in a loop like u said:

Citizen.CreateThread(function()
while true do
Citizen.Wait(500)
if GetVehiclePedIsUsing(GetPlayerPed(-1)) == Config.truck.hash then
RemoveBlip(currentBlip)
exports.pNotify:SendNotification({
text = “Go to next point”,
type = “success”,
timeout = math.random(4000, 4000),
layout = “bottomCenter”,
queue = “global”
})
setMapBlip(604.2412, -437.7084, 25.87468)
MissionText(‘Cops have been larmed’, 10000000)
end
end
end)

but i maybe put it wrong beacuse it does not work

The baseevent script triggers a serverside event when a player is entering a vehicle(enteringVehicle) and one when finished entering(enteredVehicle).
Or you could like @BitterFuck said just create your own thread and where it checks if the player entered a vehicle

I edited the code that you posted, a bit.

Explanation of the Edited code:
You don’t need to use Citizen.CreateThread or Citizen.Wait. Just use CreateThread and Wait
PlayerPedId does the same as GetPlayerPed(-1) but faster.
GetVehiclePedIsUsing is just returning you the Vehicle ID and not the hash/model. So you first need to get the model using GetEntityModel.
And since you have the model now you should change the hash config to model and then use the models and not the hashes of the vehicles. It’s easier to read.

So this should work.

CreateThread(function()
    while true do
       Wait(500)
       if GetEntityModel(GetVehiclePedIsUsing(PlayerPedId())) == Config.truck.model then
          RemoveBlip(currentBlip)
          exports.pNotify:SendNotification({
             text = “Go to next point”,
             type = “success”,
             timeout = math.random(4000, 4000),
             layout = “bottomCenter”,
             queue = “global”
          })
          setMapBlip(604.2412, -437.7084, 25.87468)
          MissionText(‘Cops have been larmed’, 10000000)
       end
    end
end)

i did this but did not work. I think it might be something with the config.
I wrote it like this in the config:
Config = {
ped = {
hash = “a_m_m_eastsa_02”,
pos = vector4(-794.3625, -726.3316, 26.29991, 270.69),
weapon = ‘WEAPON_MICROSMG’
},

truckped = {
	hash = "g_m_y_korean_01",
	pos = vector4(-732.2573, -728.5254, 29.12166, 91.69),
},
truck = {
	model = 'mule3',
	pos = vector4(-728.6955, -726.5715, 29.86137, 89.56),
}

}

is it right?

should be working, are you getting any errors? in F8(Console)

i get one error but i don’t think it makes any diffrence beacuse i deleted that function to check but it did no diffrence

image
image

I am sorry, for the late answer.
Well it makes it very hard for me to help you debug the code without actually being able to completely see it.
By the images i sadly can’t make out the error why this isn’t working.