Vehicle lock system sync bug?


I just started scripting a server on FiveM, and I was trying to make my own lock/unlock vehicle system (without any menu or command).
The main method I used to do that is this simple one :

-- To lock
SetVehicleDoorsLocked(vehicle, 2)
-- To unlock
SetVehicleDoorsLocked(vehicle, 0)

Sounds pretty obvious, and as I understand, everyone uses this method.
But after many simple tests, on 2 machines, I noticed that when two clients alternatively lock/unlock one car, the “DoorsLock” parameter gets unsynced between clients.

For exemple :

  • Client 1 takes a random car
    – DoorsLocked = 0 for both players –

  • Client 1 locks the car
    – DoorsLocked = 2 for both players –

  • Client 1 unlocks the car
    – DoorsLocked = 0 for both players –
    ==> So far so good

  • Client 2 locks the car
    – DoorsLocked = 0 for Client 1 –
    – DoorsLocked = 2 for Client 2 –
    ==> Sync problem

At this point, the DoorsLocked flag has two different values, and get synced when one client tries to enter the vehicle :

  • if client 1 enters the vehicle
    – DoorsLocked = 0 for both clients –
  • if client 2 try to enter the vehicle
    – DoorsLocked = 2 for both clients –

It seems that this bug can be reproduced with Vehicle Controls GUI v2 too, and I was wondering if it was a common problem with FiveM, or if I was the only one with this bug (before posting it in the “Bug reports” section)

I’m not very good at sending data to the server yet as I have not practiced but. If you want to sync it your gonna need to send data from the client to the server and from server back to a client.

Okay, so I should send an event to the server to send to every client the SetVehicleDoorsLocked instruction ?
I just tried this, and it’s the same issue :confused:

I also noticed this : the entity “id” of a vehicle is not the same from a client to another, so calling from server to all clients has no effect (has I suspected)

I would try and set it to a variable maybe. Idk I have never really tried to mess with vehicles to much honestly.

Yeah no, it’s strange… I will leave it like this, it’s not very important.
Thanks for the replies :wink: