Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

how do i pick a random mesh and textureid from table?

to elaborate, how would i get the missile to use a random mesh and texture id from an table i really dont know where to start, ive read the wiki, tried googling for a solution and probably some more. this is what i have right now

local mesh = {55,33,16,4}
local texture = {22,6,11,5}

so yeah i want the meshid to match the textureid lets say that the meshid is 55, then i want the textureid to be 22 meshid is 33, textureid is 6 and so on

1 answer

✓ Accepted answer

One really simple way to do this is to use a numeric for loop:

local mesh = {55, 33, 16, 4}
local texture = {22, 6, 11, 5}
local Storage = {} -- Make a table to store patterns
for i = 1, #mesh do -- This doesn't really matter because I'm assuming that your tables are going to have equal lengths anyway
	table.insert(Storage, mesh[i])
	table.insert(Storage, texture[i])
end

If you otherwise want it to be completely randomized, I would use math.random():

local mesh = {55, 33, 16, 4}
local texture = {22, 6, 11, 5}
local Storage = {} -- Make a table to store randomized patterns
local ChosenMesh = mesh[math.random(1, #mesh)]
local ChosenTexture = texture[math.random(1, #texture)]
table.insert(Storage, ChosenMesh)
table.insert(Storage, ChosenTexture)

Using a for loop to get the values by index places them in a table so that for every 2 values in a table the pattern is mesh[i] followed by texture[i]. Using math.random() randomly selects them from the tables and stores them in random patterns.

4 comments

0

alright, ill try that

0

how would i get the id to "MeshId = id from table"

0

The MeshId is always an odd number index in the storage table if you did it the first way. TextureIDs are even number indices.

0

So that means Storage[1], Storage[3], Storage[5] and Storage[7] are all MeshIds.

This discussion is preserved as it was. New answers, comments, and votes are closed.