Hello, I am new to scripting and I am trying to make a script where a tagged part has a chance of deleting and has its color changed to one of the three colors.
Thank you for your time.
local CollectionService = game:GetService("CollectionService")
local defaultColor = BrickColor.new(163, 162, 165)
local part = CollectionService:GetTagged("RockColor")
local rockColors = {
BrickColor.new(107, 122, 145), -- Red
BrickColor.new(86, 98, 116), -- Green
BrickColor.new(117, 134, 158) -- Blue
}
local function changeColor(brickColor)
part.BrickColor = brickColor
end
local function deletePart()
part:Destroy()
end
for _, part in ipairs(CollectionService:GetTagged("RockColor")) do
if part.BrickColor == defaultColor then
local randomChance = math.random()
if randomChance < 0.5 then
local randomColor = rockColors[math.random(1, #rockColors)]
changeColor(randomColor)
else
deletePart()
end
end
end