Adapt your scripts to OneSync
OneSync is FiveM's entity synchronization system, enabled by default since 2020. It changed fundamental rules: entities are owned by specific players, the default culling radius is 424 units (entities beyond it are not synced to a client), and events must target the right players. If your resource predates OneSync or you learned from an old tutorial, this lesson fixes the patterns that silently fail.
Build it
Check entity ownership before modifying
The wrong way:
-- WRONG: may fail silently if another player owns this vehicle
local veh = GetVehiclePedIsIn(PlayerPedId(), false)
DeleteEntity(veh) -- only works if YOU own it
The right way:
-- RIGHT: check ownership first
local veh = GetVehiclePedIsIn(PlayerPedId(), false)
local netId = NetworkGetNetworkIdFromEntity(veh)
local owner = NetworkGetEntityOwner(veh)
if owner == PlayerId() then
DeleteEntity(veh)
else
-- Ask the server to request ownership transfer
TriggerServerEvent('myresource:requestDelete', netId)
end
Server-side:
RegisterNetEvent('myresource:requestDelete', function(netId)
local entity = NetworkGetEntityFromNetworkId(netId)
if entity and DoesEntityExist(entity) then
DeleteEntity(entity) -- server can always delete
end
end)