Hey, there! I have made a table that basically stores the player’s ID and message. Sadly, if two messages with the same ID are found, the table removes one! What can be done?
Here’s an example code:
local GeneralChats = {
[122227420] = "Hey there.", --This one get's deleted automatically
[122227420] = "Another message from me!",
[122227425] = "Adopt me is casino for kids",
}
The problem is that the chat system I’m making needs to save multiple messages. When a player sends a second message, then the first message gets deleted, which I don’t want!
What? That isn’t even possible. You just said if 2 ID’s matched, one would be deleted. Do this
generatedId = math.random(1, 100000) --you can do whatever you want
while GeneralChats[generatedId] do
generatedId = math.random(1, 100000)
end
--then just do other stuff
Since you try to assign a new value to the same key in the table, the new value will overwrite the old value. Instead of that, have you considered assigning an array to the player’s user id instead?
Something like this:
local GeneralChats = {
[122227420] = {
"Hey there.",
"Another message from me!",
},
[122227425] = {
"Adopt me is casino for kids",
}
}
In this case, you would append new messages to the end of the array and the messages will stay in the order they were added.