[Needs help ASAP] How to add array limit


- Br, iSyriux

Hey guys if anyone could help me that would be great because I haven’t recieved much help lately

if #array >= maxNumbers  then

#array[5] = nil

table.insert(arrayName, Value)


Like that?

Yes but table.insert inserts the value on the next one so if you delete the maximum value in the array then it won’t add any new ones because the new ones are always the maximum

Why don’t you just use table.remove then?

(it’s early for me when I’m writing this so sorry if it’s not that helpful)

??? table.remove works just like table[number]=nil
I’m trying to move all the values in the array up and add the new value into the first slow, and the maximum slot gets deleted

-- Search For A Value
function FindIndex(Array,Text)
   for i = 1,#Array do
      if string.match(Array[i],Text) then
         return i

-- Removing Last Value
Array[#Array] = nil 
-- Putting a # and the array name gives length of array
-- This means that the last value will be selected

-- Adding to the start

What is “FindIndex” for? Why did you include that if you didn’t even use it?
Also, in the devhub documentation the place where you put the new value is in the middle?

Are you sure you know what you’re doing? have you even tested it?

I’m not on studio right now, but if you insert it at index 1 or 0 it should be at the start.

as for the find index its just something I added for if you want to find something within the list.

You can specify the index when inserting array elements. The remaining elements will be shifted down.

local array = {"ag","sag","rogi","dong","seat"}
local maxSize = 5

-- test
table.foreach(array, print)

-- remove excess
for i = #array, maxSize, -1 do
	table.remove(array, i)
-- add to beginning
table.insert(array, 1, "shd")

-- test
table.foreach(array, print)