This repository was archived by the owner on Apr 29, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 675
This repository was archived by the owner on Apr 29, 2025. It is now read-only.
[Bug] Exiting multiple zones at once #712
Copy link
Copy link
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
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:
- Enter multiple zones so they are registered in
exitingZones. - Move out of those zones simultaneously, triggering the exit logic.
- The script attempts to iterate through
exitingZones, but the list is altered mid-loop. - The error occurs when trying to access
exitingZones[i].idon anilvalue.
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
exitingZonesinitially contains the correct number of zones.- After calling
onExit(), the size ofexitingZonesunexpectedly decreases, leading to anilreference. - This issue happens because
onExit()modifiesexitingZonesdirectly. - Suggested fix: Iterate over a copy of
exitingZonesinstead 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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working