Hi guys this is my small code giving a car a state bag and based on this state bag i am doing other things like disabling engine and show him notification as shown in my code below.
--client
function ImpoundVehicle (TargetVeh)
local vehProps = ESX.Game.GetVehicleProperties(TargetVeh)
local vehEntity = NetworkGetNetworkIdFromEntity(TargetVeh)
Entity(TargetVeh).state:set('Clamped', true, true)
end
Citizen.CreateThread(function ()
while true do
while ESX == nil do
Wait (0)
end
if IsPedInAnyVehicle(PlayerPedId(), false) then
local veh = GetVehiclePedIsIn (PlayerPedId(), false)
if Entity(veh).state.Clamped == true then
ESX.ShowHelpNotification ("This Vehicle Is Impounded Call Mechanic.", true, false)
SetVehicleEngineOn (veh, false, true, true)
end
end
Wait(2000)
end
end)
the problem here is when i use this function on my car and ride my car and try to turn engine on the engine gets off auto and it gives me the notification as shown but when i use the function on my car and another player come and enter my vehicle he can move with it and no notification appear to him my question here isn’t the state bags has to be synced over all clients ? or i have to manually trigger server event and then send back trigger client event to all clients to be synced ? or i have to set it in server side so it will be synced for all clients and if i have to server side can any one give me that block of code bec when i do it myself it gives me strange error as shown below
--server side
RegisterNetEvent("ClampVehicle")
AddEventHandler("ClampVehicle", function (VehObj)
local veh = NetworkGetEntityFromNetworkId(VehObj)
while not (DoesEntityExist(veh)) do
Wait (0)
print("Getting Vehicle ... ")
end
Entity(veh).state.Clamped = true
clampedVehs[VehObj] = veh
end)
it gives me this error