Create a new table with a unique name from RemoteEvent data

Is there a way to create an array/ table with a unique name From the data that you get from a RemoteEvent?

For Example

I have a player value and an integer, I sent them through the RemoteEvent and I want to put them in a table, then when another player value and integer is sent through it will create a table with a different name so that it doesn’t overwrite the original table.

This is for a queue system that I’m making where it takes 3 pieces of information and puts it in a table then puts that table into the Main Queue table, but I don’t want the requests to be overwritten.

I really hope I made sense while writing this, It’s a bit hard for me to explain what exactly it is that I want. Any help would be greatly appreciated.

Well, you can use this to generate a random string:

local random = Random.new()
local letters = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}

function getRandomLetter()
	return letters[random:NextInteger(1,#letters)]
end

function getRandomString(length, includeCapitals)
	local length = length or 10
	local str = ''
	for i=1,length do
		local randomLetter = getRandomLetter()
		if includeCapitals and random:NextNumber() > .5 then
			randomLetter = string.upper(randomLetter)
		end
		str = str .. randomLetter
	end
	return str
end

local randomNameForTable = getRandomString(math.random(5,25),true)
1 Like

After I get the random string of letters how do I apply that to be the name of the table?

Use the string to make the table

(character limit)

1 Like

as in

local getRandomString(math.random(5,25),true) = {}

?

I’m sorry I just dont understand

So if I’m understanding this right, you just want a queue system where the queue items are also tables? If so, just use table.insert() to add the table to the queue table.

1 Like

I will do that, but when another request comes, wouldn’t the table get overwritten with new data? So at most I would have only 1 things queued?

table.insert will add a new item to the end of the table.

local list = {'a','b','c'}
table.insert(list,'hi')
print(list)

Output:

{a,b,c,hi}

The same will work with table nesting.

1 Like

So does this mean that the Items in the queue will be cached from when they were added?

Unless you change the order of the table using something like table.sort or something, yes. Tables by default will be ordered in FIFO (First In / First Out).

1 Like

They won’t be overridden they will just be added to the table man

1 Like

Thank you, this does make a lot of sense and definitely more efficient than generating random names for every table which was what I had in mind.

also one other quick question, if I use table.remove() will that affect the cached tables?

It will remove that spot in the table completely.

local list = {'a','b','c'}
table.remove(list,2)
print(list)

Output:

{a,c}

Although, you’ll likely just want to remove the first spot.

(Also sorry for the late response, I had to do something.)

I understand that part, but I’m asking if I remove one table in the queue table will the others be affected the same way you mentioned they would be affected if I used table.sort()?

I’m not sure what you mean by that, but the example above should explain how table.remove works. It won’t change the order of anything in the table, but it will remove one item and move everything ahead of that item back one. So if you remove the second item, the third item will become second. table.sort will change the order of the table based on the order function you give it.

In your case, all you’ll have to do is:

table.table(list,1)

so 3 moving to 2 wont affect the cache?

I don’t know what you mean by cache, but it won’t change the order of the items, just the positions after the removed item to -1 of what it was.