[Help] No peds with c#

I try to get rid of peds and vehicles on my server with help of this topic but in c# it does’n work.
My code:

class Environment : BaseScript
    {

        public Environment()
        {
            Tick += OnTick;
        }

        public async Task OnTick()
        {
            
            API.SetVehicleDensityMultiplierThisFrame(0.0f);
            API.SetPedDensityMultiplierThisFrame(0.0f);
            API.SetRandomVehicleDensityMultiplierThisFrame(0.0f);
            API.SetParkedVehicleDensityMultiplierThisFrame(0.0f);
            API.SetSomeVehicleDensityMultiplierThisFrame(0.0f);
            API.SetScenarioPedDensityMultiplierThisFrame(0.0f, 0.0f);

            Vector3 pos = LocalPlayer.Character.Position;
            API.RemoveVehiclesFromGeneratorsInArea(pos.X - 500.0f, pos.Y - 500.0f, pos.Z - 500.0f, pos.X + 500.0f, pos.Y + 500.0f, pos.Z + 500.0f, 1);

            API.SetGarbageTrucks(false);
            API.SetRandomBoats(false);

            API.SetPlayerWantedLevelNoDrop(LocalPlayer.Handle, 5, true);

            await Delay(1000);
        }

    }

Can anybody help me? Thanks.

Don’t delay the tick for 1000 milliseconds, these natives need to be ran every tick:

SetVehicleDensityMultiplierThisFrame
SetPedDensityMultiplierThisFrame
SetRandomVehicleDensityMultiplierThisFrame
SetParkedVehicleDensityMultiplierThisFrame
SetSomeVehicleDensityMultiplierThisFrame
SetScenarioPedDensityMultiplierThisFrame

I’ve tried to change delay to 1 or 0, still not work :frowning:

don’t add any delay. OnTick already runs every tick and you don’t need to add a delay. Only add delays if you are in a long while/for loop. or doing a lot of things every frame.

1 Like

ohhh. thank you very much