(RESOLVED) - Why it doesn't work?

Hi guys,

I tried to convert the LockDoors script to close and open the cars without going through the /lock but by the G key.
Something is wrong, here is my script

car = false
lastCar = nil

Citizen.CreateThread(function()
    while true do
        Citizen.Wait(0)
        if IsControlJustPressed(1, 47) then
            Citizen.Trace("Control Was Pressed")

            car = GetVehiclePedIsIn(GetPlayerPed(-1), false)

            if not car and lastCar == nil then
                TriggerEvent("chatMessage", "ERROR", {255, 0, 0}, "You have to sit in a vehicle to set it as yours.")
                return
            elseif car then
                lastCar = car
            end

            lockStatus = GetVehicleDoorLockStatus(lastCar)
            if lockStatus == 0 or lockStatus == 1 then
                Citizen.Trace("DOORS ARE LOCKED")
                SetVehicleDoorsLocked(lastCar, 2)
                SetVehicleDoorsLockedForPlayer(lastCar, PlayerId(), false)
                TriggerEvent("chatMessage", "INFO", {255, 255, 0}, "Door is now ^1locked^0.")
            else
                Citizen.Trace("DOORS ARE LOCKED")
                SetVehicleDoorsLocked(lastCar, 1)
                TriggerEvent("chatMessage", "INFO", {255, 255, 0}, "Door is now ^2unlocked^0.")
            end
        end
    end
end)

The problem is that the script displays directly Door is now Locked.
A solution ? I am blocked … :frowning:

Can you tell me what you did to get this too work?

Thanks ahead of time.

I started everything again to have a clean base and I realized that the variables car and lastCar was never nil so I think it’s due to it.

Otherwise here is the script I did, it also checks that the player is within 5 meters of the car to be able to close it and open it. The key is U.

https://mega.nz/#!CgVknTCS!4hEddrQ9jLza2id4RwDvF2NL6jjYb9v9XBerNpoeRqs

I do not try it in multiplayer but it should work. Keep me informed :slight_smile:

It seems to be working :slight_smile:

Thanks again for the code, greatly appreciated!!

Can you refresh link?)
Please

https://forum.cfx.re/t/release-locksystem-v2-0-3-updated-the-07-03-at-11pm/

But I do not work on it right now and there are people who have bugs with it.

i need system without keys .I need press button and car open and press button car lock and its all what i need.