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

Random BrickColor, how about Random Materials?

How would i make that?

1 answer

✓ Accepted answer
BrickColor.Random()

Makes a Random BrickColor.

Making a random Material is harder only because Material is an Enum, as opposed to an Object like BrickColor.

--First, let's make a dictionary of the possible Materials:
local mats = {}
for _, v in pairs(Enum.Material:GetEnumItems()) do --Rather than hard code the values, populate the list based on the *current* Materials.
	mats[v.Name] = v
end

function MaterialRandom() --let's make this a function...
	return mats[math.random(#mats)] --And return one of the random members of that Table.
end

2 comments

0

Is it also possible to do a math.random on a table of strings of the materials?

0

Yeah it is, but it will return the position instead of the value itself. math.random(1, #mats) will return a random POSITION of a material rather than the actual material itself. To refer to the value, you would set a variable for the position, and use mats[VARIABLE]

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