Hey again! Today, I have a script that when the game starts, it randomizes the color and material of parts that are in a folder! Take a look. Note: I have other versions of the script that DO work, I just wanna sort out how to use one script to randomize a couple of parts.
local shelvedProducts = game.Workspace.ShelvedProducts:GetChildren()
local Materials = Enum.Material:GetEnumItems()
local RandomMaterial = Materials[math.random(#Materials)]
for _, product in pairs(game.Workspace.ShelvedProducts:GetChildren()) do
shelvedProducts.Material = RandomMaterial
shelvedProducts.Color = Color3.fromHSV(math.random(0,255)/255, 1, 1)
end
When I run the game, I get no error but the parts do not randomize. Any idea what could be the problem here?
local products = game.Workspace.Products:GetChildren()
local Materials = Enum.Material:GetEnumItems()
local RandomMaterial = Materials[math.random(#Materials)]
for _, product in pairs(game.Workspace.Products:GetChildren()) do
products.Material = RandomMaterial
products.Color = Color3.fromHSV(math.random(0,255)/255, 1, 1)
end
Scripts donât have a color property youâre trying to change the color of the script but scripts donât have a color property we first check if it is a part before we change itâs color. Since the script itself is located in the folder it will also loop through the script.
local products = game.Workspace.Products:GetChildren()
local Materials = Enum.Material:GetEnumItems()
local RandomMaterial = Materials[math.random(#Materials)]
for _, product in pairs(products) do
if product:IsA("BasePart") then
product.Material = RandomMaterial
product.Color = Color3.fromHSV(math.random(0,255)/255, 1, 1)
end
end