How to set pointer to nil

How would I replicate this in lua

c++
*pointer_table = nil

if I do in lua

pointer_table = nil

it will just make the variable = nil and not the actual table

1 Like

What are you trying to do exactly? You can’t really “un-declare” things this way, you only set its value as, well, nothing.

Once all references to an object are gone, id est the variables are all nil or out of scope, the object will be garbage collected.

Why do you need the table to be nil?
If the variable is nil then you could set it to a table…

I don’t have the the location of the original table though (because it’s in an array at a random index) but I have a variable that points to it, I want to set the table to nil through the variable.

You can use table.find to find where in the array it is and then set the value at that index to nil.

1 Like

That uses linear search and would be very slow and inefficient in an array with 10,000 indexes

To the extent of my knowledge, pointers are not possible in Luau, unfortunately. What you are attempting to accomplish is not going to work. This may be confusing since referencing a table and then adjusting the reference’s children will affect the actual table.

1 Like

How urgently do you need it removed? Can you make a garbage cleanup trawler that will go through the table in a low-priority manner and find the objects to set to nil? You could catch multiple with one pass this way.

1 Like

So that’s sort of what I do, OnPlayerRemoving I loop through the table and take out what I don’t want.

I really just wanted to know if I can do it an easier way but it seems in Lua you can’t.

Thanks for the help though.

1 Like