Table item added/removed

Hello

I am attempting to make something that detects if an object has entered a specific zone. And fire it like an event. For example of the tables:

local Objects = {
        {Object = workspace.Baseplate},
        {Object = workspace.Part},
        {Object = workspace.Wedge},
}

And it will keep resetting the table for all parts within a certain radius.
For ex:

local Objects = {
        {Object = workspace.Baseplate},
        {Object = workspace.Part},
        {Object = workspace.Wedge},
}

--Next scan
local Objects = {
        {Object = workspace.Baseplate},
        {Object = workspace.Part},
        {Object = workspace.Item}, --Something new
}

and I would like to figure out which elements are missing or added.

You could use WorldRoot | Documentation - Roblox Creator Hub if you’re fine with a rectangular “zone”.

Or you could use this module for other Region3 shapes: Rotated Region 3 Module

Or you could write a relatively simple function that checks descendants recursively for their center positions. This has the downside of not taking into account parts that are only partially inside the sphere “zone”.

I’m actually looking for a fully spherical region. So magnitude would be much more efficient, however, I am attempting to detect if a new part has entered the radius.

Not sure why you’re encapsulating these Objects inside a table {Object = Instance}. Seems unnecessary.

But I digress, do you have a specific list of instances you’d like to check? Because scanning the entirety of workspace would be a huge performance issue.

Actually reading over @nicemike40’s reply. That module he recommended includes Spherical Region3s.

Ah, I actually omitted the distance and Unit indexes for the table.

However, my original question still stands, is there any way to detect a new value in a table (not dictionary) and a missing value.

Unfortunately as far as I am aware it is not possible to do this with just a normal array, you’d have to use __newindex on a dictionary with metatables.

2 Likes

Oh, that’s unfortunate. I thought about putting it in a dictionary, but decided to ask around if there were any alternatives.

Thank you for the help!

1 Like