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```