What method to add values to array with for loop

	local IDs = require(game.ReplicatedStorage.IDs)
	id = {};
	for IDindex,#IDs do
		
	end

Looking to add values into the id array equal to the number of IDs in the modulescript.
For example, if IDs contains
Ids = {
[1] = 0;
[2] = 0;
}

I want to create [1] = 0 and [2] = 0 in this new array.

is there a reason you cant just

local IDs = require(game.ReplicatedStorage.IDs)
	id = {}
	id = IDs

but if you really wanted to you could

local IDs = require(game.ReplicatedStorage.IDs)
	id = {}
	for i, v in pairs (IDs) do
    table.insert(id,i,v)
    end
1 Like

Yes, Iā€™m trying to auto-generate the DataStore data using any IDs in my modulescript, to avoid having to edit too many things every time I add an additional item ID. The IDs in the modulescript have different values assosciated with them.

You could add the values within IDs to id by using the table.insert method.

local IDs = require(game.ReplicatedStorage.IDs)
local id = {}
for _, v in ipairs(IDs) do
    table.insert(id, v)
end

I hope this helped. :slight_smile:

EDIT
Just saw the last sentence. You could set the index in id to the value in IDs.

local IDs = require(game.ReplicatedStorage.IDs)
local id = {}
for i, v in next, IDs do
   id[i] = v -- Say `i` was 1111 and `v` was 5, `1111` would be added to `id` as an index to `5`
end
1 Like

um there is one slight error with your script, your looping through an empty table, but besides that yours is the solution i believe

1 Like