Skip to content
This repository was archived by the owner on Apr 29, 2025. It is now read-only.
This repository was archived by the owner on Apr 29, 2025. It is now read-only.

[Bug] Exiting multiple zones at once #712

@Axel2222

Description

@Axel2222

Describe the bug

When exiting multiple zones at the same time, exitingZones[i].id throws an error because exitingZones is modified while iterating. Specifically, onExit() removes elements from exitingZones, causing the loop to access nil values.

The error message:

SCRIPT ERROR: @ox_lib/imports/zones/client.lua:180: attempt to index a nil value (field '?')

To Reproduce

Steps to reproduce the behavior:

  1. Enter multiple zones so they are registered in exitingZones.
  2. Move out of those zones simultaneously, triggering the exit logic.
  3. The script attempts to iterate through exitingZones, but the list is altered mid-loop.
  4. The error occurs when trying to access exitingZones[i].id on a nil value.

Expected behavior

The loop should iterate over all exiting zones without errors, and all onExit() functions should execute correctly.

Screenshots

N/A (since it's a runtime error, logs are provided below instead).

Additional context

  • exitingZones initially contains the correct number of zones.
  • After calling onExit(), the size of exitingZones unexpectedly decreases, leading to a nil reference.
  • This issue happens because onExit() modifies exitingZones directly.
  • Suggested fix: Iterate over a copy of exitingZones instead of modifying the table while iterating.

Debug logs showing the issue:

exitingSize
6
exitingZones
[INFO] -- List of zones
exiting
1
exitingZones[i].id -> 3 (valid)
exiting
2
exitingZones[i].id -> 4 (valid)
exiting
3
exitingZones[i] -> nil (error occurs here)

This issue may require refactoring how exitingZones is handled in the iteration.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions