Insert object in an already existing array located in a table

Hello! I’m trying to get started with some tables needed for my current project. I encountered an issue, in which I don’t know how to insert “v” in the RoomTypes array automatically. Is this possible? My current method errors out when trying to do ["RoomTypes"]. Keep in mind this is a module script.

local rooms = {
	["RoomTypes"] = {};

for _,v in pairs(script.Parent:GetChildren()) do
	if v:IsA("Folder") then table.insert(rooms, ["RoomTypes"], v)

return rooms

Thanks in advance!

The reason you’re having this issue is because 2nd argument to the table.insert must be either a Variant or a number. In this case, what you meant to do is to type table.insert(rooms.RoomTypes, v)

1 Like