Nil a Table dont works

local match = {}

match[tostring(player.UserId)] = {}

match[tostring(player.UserId)] = nil	

Nil works

table.insert(match[tostring(playerWhoCreatedMatchId)], tostring(player.UserId))

match[tostring(playerWhoCreatedMatchId)][tostring(player.UserId)] = nil

Nil dont works
Why?

Setting the value to nil does not work because you are inserting a value into an array, not a dictionary.

Okay what should i do then?


table.insert creates arrays, which means that the indexes in the table are ordered numbers rather than the IDs themselves. This also means that you need to use a value’s order in the table to reference it if it was added to the table with table.insert.

You can use table.find to find the user ID’s place in the table dynamically:

local t = match[tostring(playerWhoCreatedMatchId)] -- making this a variable just to make it look better

table.insert(t, tostring(player.UserId))

t[table.find(t, tostring(player.UserId))] = nil
3 Likes

Thank you so much, that worked!