How can i make the script between different texture IDs

Ello DevForum,

I have a problem. I have a script where a player can placedown a ammo box wich is just a meshpart with scripts in it etc.

How can i make the script apply randomly a meshID i have set in a table in the script example like

local AmmoBoxMeshes = ["51254","6346345"]

You could do MeshId = “rbxassetid://“…AmmoBoxMeshes[math.random(1,#AmmoBoxMeshes)]

Make sure you do research first, this should be a fairly easy question to find the answer to!
In order to get the ID from the table, use this line of code:
local meshId = AmmoBoxMeshes[math.random(1,#AmmoBoxMeshes)]

Then just apply that ID to the meshpart.
MeshPart.MeshTexure = "rbxassetid://"..meshId

i though i would find a answer in the internet but i found one about how to pick random players but my brain stupid to convert it xd

1 Like

for what does the number stand for in “1” does it mean to pick 1 ID ?

From the Dev Wiki regarding math.random:

This function is an interface to the simple pseudo-random generator function rand provided by ANSI C. (No guarantees can be given for its statistical properties.) When called without arguments, returns a uniform pseudo-random real number in the range [0,1). When called with an integer number m, math.random returns a uniform pseudo-random integer in the range [1, m]. When called with two integer numbers m and n, math.random returns a uniform pseudo-random integer in the range [m, n].

The ‘1’ prevents math.random from selecting a value lower than 1. In this case, this is because you don’t want to select a nonexistent key from the table like “-1538232” or “0.”

For reference, the #AmmoBoxMeshes part of AmmoBoxMeshes[math.random(1,#AmmoBoxMeshes)] is the upper bound to the table because it uses the length of the table*.

*or more precisely, the highest number key in the table

2 Likes