Table Can Not Be Cyclic?!

While testing in Studio I don’t get any errors but I get this Error while playing Online.

Hey RuizuKun_Dev. Please insert screenshots of the error or the code so it’s easier to assist you.

The output literally saids “Table Can Not Be Cyclic”, I decided to not insert a screenshot because it won’t be beneficial.

A cyclic table is a table that referenced itself. So they look a little like a = {} a[1] = a. You may be attempting to send one of these through an event.

Why is this only a problem for Online games, and why is it a problem at all?

I’m using __index and setmetatable for my code, can this be causing the issue?

Seems the error is only showing in live games
Cyclic Tables Error Will Only Occur In Live Games

It’s messing a lot of people up, not a lot of people finishes code and goes straight to live game to test usually we play solo. You could probably try the test server in studio mode, see if it comes up there.

1 Like

No, it doesn’t, only errors in an Online game.

I would like to know why or what is causing this and if I should fix my code or this will be fixed.

Is this a new issue or it’s been around?

Please refer to the link he provided - a reproducible engine bug where the report was posted back in May suggests that it’s been around for a while. Unfortunately, no one (except the OP) has replied to said post. Might want to bump his topic.

This also shows that it’s been around relatively recently as well (June).

I’m looking for a solution so I probably won’t bump his thread, doesn’t seem like there’s a point to that as the Engineers will get to it when they do.

More importantly is what I need to do;

If it’s intended behavior then I’ll change my code, if not I’ll need a band aid until it’s resolved

The best solution would be to go through your table and any references to your table and check if you did something where you attempt to set a component of the table to the table such as

local tableA = {}
tableA.self = tableA

The engine bug report thread also gives a possible solution, though that depends on how you’re using your table, in this case, alongside BindableEvents.

I’ve read the Thread he’s using a Bindable, I’m using a RemoteEvent I don’t think the solution would be compatible but let me know if I’m mistaken.

I am using __index in my code would that be a possible cause?

Table.__index = Table

Unfortunately, I’ve never been able to get my head around metatables, nor have I encountered this issue with tables not being able to be cyclic before, so I won’t be able to provide much help on the matter. :pensive:

Though you could always try and copy your code into another place, make sure that place encounters the error, remove code that is irrelevant whilst remaining functionality, then try and change your Table._Index = Table to something else to see if that fixes the issue.

In this case __index is not a metatable, it’s a key.
So yeah, that’s probably the cause of it.

You could possibly solve it by manually setting the metatable, but you’d need to re-set the metatable on server (or wherever you’re sending) since metatables don’t get transferred over events.

local x = {}
  return self = setmetatable({...}, {__index = x})

I’m not sure I can do that, but let me know

Table[SubTable] = setmetatable({},Table)
Table[SubTable].__index = Table[SubTable]

Table contains methods and SubTables

I’m also sending the SubTable to the Client, I don’t need it’s Metatable there so that’s not an issue in my particular case.

Metatables don’t get transferred over events, you won’t be able to access those values either way.

Since the __index metamethod only fires after a table has been indexed with a key it does not contain, setting __index to the parent table of the metatable (which has already been indexed), is both pointless and understandably buggy. I’m surprised you don’t stack overflow

You’re thinking of __newindex, not __index.

__newindex fires when you’re trying to set a nonexistent key to some value.
__index fires whenever you try to index some key.

Rather, __index fires whenever you try to index some key which is not found in the table.

If the key you index exists already, __index will not fire

Yes, I don’t need that.

I could probably separate my Data Table that will be sent to the Client so there will be no Errors.

You read my code wrong pal,

Table[SubTable] = setmetatable({},Table)
Table[SubTable].__index = Table[SubTable]

I set Table[SubTable] to Table, it’s parent

I set it’s index to Table[SubTable], itself (because I have another SubSubtable inside the Subtable with a Metable set to the Subtable)

My code runs fine and I’m not getting any stack overflows, but please let me know if I’ve missed something