Hey there,
Im working on a script right now and want the vehicles that the user spawns (around 8 vehicles controlled by peds), only collide with that user, and no other player, I’ve busted my head numerous times trying to make SetEntityNoCollisionEntity
work in between the vehicle handles that I store server side and send to each client to disable collisions each frame.
I’ve went searching deep into the forum for answers and learned about “entity owning” which in this case would explain why on another client, I’m not able to perform operations on those vehicles not owned by that client.
The following code is the one I use to handle the collisions. entitiesNoCollisions
contains an array of vehicle handles created by the other client to disable collisions on the current client
Citizen.CreateThread(function()
while true do
Wait(0)
for k, v in pairs(entitiesNoCollision) do
SetEntityNoCollisionEntity(PlayerPedId(), v, false)
if (userCar ~= nil) then
SetEntityNoCollisionEntity(userCar, v, false)
end
DisableCamCollisionForEntity(v)
end
end
end)
I tried creating those vehicles server side, & using their network ID to retrieve their handle in each client, this went without success, I got this error over and over
this was the code I used and tested server side to create the car when the previous code didn’t work
RegisterServerEvent('SoloRaces:CreateVehicle')
AddEventHandler('SoloRaces:CreateVehicle', function(model, x, y, z, h, isNet, isScript)
local Source = source
local entity = CreateVehicle(model, vector3(x, y, z), h, isNet, isScript)
-- Wait while the entity is being created
while not DoesEntityExist(entity) do
Wait(0)
end
TriggerClientEvent("SoloRaces:SetClientResult", Source, NetworkGetNetworkIdFromEntity(entity))
end)
Help is appreciated, I’m really struggling to make this work !