Cannot convert mixed or non-array tables: keys must be strings

function WinManager:Details(winner, winnerType, gamemode, multiple, data)
	print(type(winner))
	print(type(winnerType))
	print(type(gamemode))
	print(type(multiple))
	print(type(data))
	
	ShowWinner:FireAllClients(winner, winnerType, gamemode, multiple, data) -- ERROR
end

userdata

string

string

boolean

table

Cannot convert mixed or non-array tables: keys must be strings

1 Like

Would you be able to show the data argument you’re passing to the Details function?

I don’t wanna do that as I need the players userID from the client, so I have to pass through the player itself

As the error is about a table and the data item is the only table what is contained in the data item?
Also as this is a fireclient can you show us the client code that processes this call?

RamJoT makes a good point, only the data variable is the only table you have. The reason this is an issue is because you cannot transfer tables over the server with “mixed”/“non-array” keys. So if you use different keys like data[“ID”], data[3], and data[player], the server won’t pass the table (hence the error). That is why RamJoT would like to see the contents of your data table.

The data is the players data. So it should only be ‘data[player.UserId]’ and thats it

Why don’t you just set those to strings then? data[tostring(player.UserId] will abide by what the error is spitting out, and you still keep the same key, just in a different format.

The reason your method doesn’t work is you are not providing an array; you listed keys in an unorganized format and not in sequence. That’s why player ID’s are not good keys to use in numerical form. By using a string, you are defining a set of keys that don’t have a sequence and are of the same data type.

2 Likes

Why does it have to be a string key? I’ve done this all before, using the players id as the key and it’s worked perfectly fine.

Let me reiterate that an array has a defined order - a sequence - of keys. And they always start at 1, so your data table will look like data[1], data[2], … , data[player1ID], … , data[player2ID], …

In essence, you are leaving holes in the sequence that you have not defined. You cannot do this when you send tables across the server as arrays. That is what the error is trying to tell you. That is why it has to be a string (or some other data type, just not an integer) since an integer key describes arrays. They are called dictionaries but most people just call everything tables here.

If you are still confused, I suggest spending some time here. The wiki goes over the difference between the two types of tables in more depth.

I’m guessing (and I don’t really have a source for this, but it’s based on my common sense so maybe someone can verify) that Roblox doesn’t allow disordered arrays to be sent across the server because of the extra data within the holes that are undefined. Something about hundreds of thousands of holes feels like a waste of memory to me in an ordered list.

Hope that clarified some things.

Is there a reason why doing something like this:

Event:FireAllClients(data)

works, but like

Event:FireAllClients(data, 'String')

doesn’t?

I’m not sure, but I think something like that is kind of pointless. Why not just put everything in the table? Then you only need one parameter.

I haven’t run into this before because I usually put everything in a table if the data I want to send is a large amount. Perhaps someone with more knowledge regarding this can help explain why your second block doesn’t work.