1ForeverHD / ZonePlus

Construct dynamic zones that utilise region checking, raycasting and the new BasePart.CanTouch property to effectively determine players and parts within their boundaries.
https://devforum.roblox.com/t/zone/1017701
MIT License
74 stars 115 forks source link

[Bug] "attempt to index nil with 'item'" #61

Open JimmyDeemo opened 1 year ago

JimmyDeemo commented 1 year ago

Getting this error on stopping the game in Studio;

16:39:30.400  ReplicatedStorage.Modules.Zone.ZoneController.Tracker:135: attempt to index nil with 'item'  -  Server
16:39:30.400  Stack Begin  -  Studio
16:39:30.400  Script 'ReplicatedStorage.Modules.Zone.ZoneController.Tracker', Line 135  -  Studio
16:39:30.400  Script 'ReplicatedStorage.Modules.Zone.Signal', Line 37 - function acquireRunnerThreadAndCallEventHandler  -  Studio
16:39:30.400  Script 'ReplicatedStorage.Modules.Zone.Signal', Line 48 - function runEventHandlerInFreeThread  -  Studio
16:39:30.400  Stack End  -  Studio

I believe it is linked to the fact that Zone:untrackItem cleans up itemDetail and then calls Fire on Tracker.itemRemoved:

function Zone:untrackItem(instance)
    local itemDetail = self.trackedItems[instance]
    if itemDetail then
        itemDetail.janitor:destroy()
    end
    self.trackedItems[instance] = nil

    local Tracker = require(trackerModule)
    Tracker.itemRemoved:Fire(itemDetail)
end

This uses .item in the handler, which has been cleaned up:

Tracker.itemRemoved:Connect(function(itemDetail)
    self.exitDetections[itemDetail.item] = nil
    updateItem(itemDetail, nil)
end)