So I’ve been having a trouble with writing a code. Simply it will going to give a color to every part inside a model depends on a attribute in model which is called “BulbType”. However, only 1 of the parts inside the model gets colored and other parts doesn’t gets colored. Have I done anything wrong?
local Tag = "Bulb"
local CollectionService = game:GetService("CollectionService")
function getBulb()
for _, bulb in CollectionService:GetTagged(Tag) do
if not bulb then return end
return bulb
end
end
function getBulbParts(bulb)
for _, bulbParts in bulb:GetDescendants() do
if bulbParts:IsA("BasePart") then
return bulbParts
end
end
end
function setBulbs()
local bulb = getBulb()
if bulb:GetAttribute("BulbType") == "Kill" then
local bulbParts = getBulbParts(bulb)
bulbParts.BrickColor = BrickColor.new("Really red")
elseif bulb:GetAttribute("BulbType") == "Health" then
local bulbParts = getBulbParts(bulb)
bulbParts.BrickColor = BrickColor.new("Lime green")
elseif bulb:GetAttribute("BulbType") == "Push" then
local bulbParts = getBulbParts(bulb)
bulbParts.BrickColor = BrickColor.new("Royal purple")
end
end
setBulbs()