Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Random BrickColor, how about Random Materials?

Asked by
iNicklas 215 Moderation Voter
9 years ago

How would i make that?

1 answer

Log in to vote
4
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago
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
0
Is it also possible to do a math.random on a table of strings of the materials? unmiss 337 — 9y
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] Discern 1007 — 9y
Ad

Answer this question