How to fix this error ? sombody help pls

local isInVehicle = false
local isEnteringVehicle = false
local currentVehicle = 0
local currentSeat = 0

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

    local ped = PlayerPedId()

    if not isInVehicle and not IsPlayerDead(PlayerId()) then
        if DoesEntityExist(GetVehiclePedIsTryingToEnter(ped)) and not isEnteringVehicle then
            -- trying to enter a vehicle!
            local vehicle = GetVehiclePedIsTryingToEnter(ped)
            local seat = GetSeatPedIsTryingToEnter(ped)
            isEnteringVehicle = true
            TriggerServerEvent('baseevents:enteringVehicle', vehicle, seat, GetDisplayNameFromVehicleModel(GetEntityModel(vehicle)))
        elseif not DoesEntityExist(GetVehiclePedIsTryingToEnter(ped)) and not IsPedInAnyVehicle(ped, true) and isEnteringVehicle then
            -- vehicle entering aborted
            TriggerServerEvent('baseevents:enteringAborted')
            isEnteringVehicle = false
        elseif IsPedInAnyVehicle(ped, false) then
            -- suddenly appeared in a vehicle, possible teleport
            isEnteringVehicle = false
            isInVehicle = true
            currentVehicle = GetVehiclePedIsUsing(ped, -1)
            currentSeat = GetPedVehicleSeat(ped)
            local model = GetEntityModel(currentVehicle)
            local name = GetDisplayNameFromVehicleModel()
            TriggerServerEvent('baseevents:enteredVehicle', currentVehicle, currentSeat, GetDisplayNameFromVehicleModel(GetEntityModel(currentVehicle)))
        end
    elseif isInVehicle then
        if not IsPedInAnyVehicle(ped, false) or IsPlayerDead(PlayerId()) then
            -- bye, vehicle
            local model = GetEntityModel(currentVehicle)
            local name = GetDisplayNameFromVehicleModel()
            TriggerServerEvent('baseevents:leftVehicle', currentVehicle, currentSeat, GetDisplayNameFromVehicleModel(GetEntityModel(currentVehicle)))
            isInVehicle = false
            currentVehicle = 0
            currentSeat = 0
        end
    end
    Citizen.Wait(50)
end

end)

function GetPedVehicleSeat(ped, -1)
local vehicle = GetVehiclePedIsIn(ped, false)
for i= -1, GetVehicleMaxNumberOfPassengers(vehicle) do
if(GetPedInVehicleSeat(vehicle, i) == ped) then return i end
end
return -1
end

function GetPedVehicleSeat(ped, -1)
local vehicle = GetVehiclePedIsIn(ped, false)
for i = (-1), GetVehicleMaxNumberOfPassengers(vehicle) do
if(GetPedInVehicleSeat(vehicle, i) == ped) then return i end
end
return -1
end

–Maybe that will work?

thanks but it
still same error :frowning:

Hm… It looks right to me but who knows there is probably something that were just missing. What I would do is start another function call it the same thing and code it very slowly and talk it out through my head.

function GetPedVehicleSeat(ped, -1)
local vehicle = GetVehiclePedIsIn(ped, false)
local negative = -1
for i = negative, GetVehicleMaxNumberOfPassengers(vehicle) do
if(GetPedInVehicleSeat(vehicle, i) == ped) then return i end
end
return -1
end

– Try that and see if making it a variable will fix it.

still not solved… :frowning:

hm I have no idea. kinda weird.