Jump to content

Strange thing with setVehicleOverrideLights


pa3ck

Recommended Posts

Good evening folks, I found a problem / bug in my script which is the following: If I'm using the function alone, its working well, no problem, but if 2 clients use it at the same time then it will get buggy. Sometimes it wont switch on sometimes its just blinks... Here is the code I was using:

  
--Client 
  
function lights() 
       local veh = getPedOccupiedVehicle(getLocalPlayer()) 
                 
    if veh then 
        triggerServerEvent('lightS', getRootElement(), veh) 
    end 
end 
addEventHandler('onClientVehicleEnter',getRootElement(),function() 
        bindKey( 'l', 'down', lights ) 
end 
) 
  
--Server 
  
addEvent('lightS', true) 
addEventHandler('lightS', root, function( veh ) 
    if ( getVehicleOverrideLights(veh) ~= 2 ) then 
        setVehicleOverrideLights(veh, 2) 
    elseif ( getVehicleOverrideLights(veh) == 2) then 
        setVehicleOverrideLights(veh, 1) 
    end 
end 
) 
  

Any idea / solutions?

Link to comment

On triggerServerEvent switch getRootElement() to localPlayer.

I also suggest using onClientPlayerVehicleEnter instead of onClientVehicleEnter, because the latter's source is a vehicle and the other's one is the local player - might have something to do with it.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...