How can i remove or create a child to an object inside a table?

im trying to use a table to emulate a model in workspace
this table is a clone of the model
inside the table is parts, some parts have an objectvalue inside them and others dont

here’s what a part with an objectvalue looks like in the original model

im trying to destroy() an objectvalue inside a part the in table and it nils saying value doesnt exist however, it exists and i can find it with print(part.Value)

local currentSquareOn = UtilityChess:FindSquareByPiece(clonedTable, Piece)
print(currentSquareOn.Value)

00:00:00.00 Value - Client - ReplicatedChess:160 (no error)

currentSquareOn.Value:Destroy()

00:00:00.00 ReplicatedStorage.ReplicatedChess:160: attempt to index nil with ‘Value’ - Client - ReplicatedChess:160

is there anyway to remove the Value object inside the table?

let me know if anything needs explaining, thanks

You can use :FindFirstChild(“Value”)::ObjectValue temporally aswell.

1 Like

Reread the issue. Are you maybe accidentally setting currentSquareOn to something else before currentSquareOn.Value:Destroy()?

Try an if statement:

local currentSquareOn = UtilityChess:FindSquareByPiece(clonedTable, Piece)
if currentSquareOn and currentSquareOn:FindFirstChild("Value") then
currentSquareOn.Value:Destroy()
end
1 Like

thanks for responding , i mightve found the issue
i used table.clone to a different table thats still linked to the model

clonedTable = table.clone(Boardparts)

i want to emulate and have a clone of the boardparts in a table but not linked to the workspace object; is there a way to do this?

Absolutely! Depending on how Boardparts is structured.

I’d recommend creating an empty table x = {} and looping through Boardparts to insert what you need.

Use table.insert(x, v) or map with keyx[y] = v

Let me know if you need more help.

1 Like