#table.find returning nil

21 messages · Page 1 of 1 (latest)

loud ravine
#

made a simple block placement system, but when trying to delete a block sometimes table.find returns nil even though the instance is in PlacedEntities

local Placement = {Info = {}}
Placement.Info = {
  PlacedEntities = {}
}
function Placement:Place(entity: object, placementPosition: Vector3) --// creates new block in position of mouse
    local newEntity = entity:Clone()
    newEntity.Position = placementPosition
    newEntity.Parent = workspace
    table.insert(self.Info.PlacedEntities, newEntity)
    return newEntity
end

function Placement:Delete(mouseTarget: Instance) --// deletes the block which the mouse is pointed at
    if not mouseTarget then return end
    if not table.find(self.Info.PlacedEntities, mouseTarget) then return end --// checks if target instance is a player placed object
    table.remove(self.Info.PlacedEntities, self.Info.PlacedEntities[mouseTarget])
    mouseTarget:Destroy()
end```
#

keeps happening to every 1/4th or 1/5th block

vivid pelican
#

oh

#

nvm

#

try printing the whole placement tree

#

then you could find what is going wrong

loud ravine
#

already did and everything shows up fine

#

the block is in the table and shouldn't cause any problems, but it still refuses to return true with table.find

vivid pelican
#

hm

#

oh

#

it was bc

#

you tried to use instance as a parameter

#

using instance as a parameter is not a preferred way

#

but it works

#

however if you send the instace by remote event or function

#

the instance id will change

#

@loud ravine

#

try using uniqueId

#

you should care more on specifying and identifying entities

loud ravine
#

👍 will try it out ty

#

seems to have fixed the problem, thank you !