Random Material Sphere

I am trying to spawn a sphere out of a random material yet when I run the code it only spawns in the sphere as grass.

Code

local Materials = Enum.Material:GetEnumItems() – Get a table of all the possible materials

local IgnoreMaterials = {

Enum.Material.Air; Enum.Material.Water;

Enum.Material.Rock; Enum.Material.Asphalt;

Enum.Material.Snow; Enum.Material.Glacier;

Enum.Material.Sandstone; Enum.Material.Mud;

Enum.Material.Basalt; Enum.Material.Ground;

Enum.Material.CrackedLava; Enum.Material.Salt;

Enum.Material.LeafyGrass; Enum.Material.Limestone;

Enum.Material.Pavement;

} – Materials to ignore from the list

for _, material in next, IgnoreMaterials do – Removing unnecessary materials

table.remove(Materials, table.find(Materials, material))

end

local RandomMaterial = Materials[math.random(#Materials)]

print(RandomMaterial)

workspace.Terrain:FillBall(Vector3.new(0,0,0),100,RandomMaterial)

Some of these materials are not supported by the terrain system. You will have to add these unmapped materials to your IgnoreList

Your code works. Example would be Enum.Material.WoodPlanks

However there is no terrain texture for the Enum.Material.Wood material. So it will output grass.

I don’t think there is a list for all of these unmapped materials so you will likely have to manually remove them. Alternatively, instead of a terrain blacklist, it would be much easier to just have a whitelist of what materials can be used.

local Materials = {
	Enum.Material.Grass,
	Enum.Material.WoodPlanks,
	Enum.Material.Cobblestone,
	--// add rest of materials you want to include
}

local RandomMaterial = Materials[math.random(1, #Materials)]

print(RandomMaterial)

workspace.Terrain:FillBall(Vector3.new(0,0,0),100,RandomMaterial)
1 Like