0

# How i make a text apear when all the parts in a folder are black?

Gigaset39 111
1 month ago
Edited 1 month ago

Hello im have a script that, when you touch a part it turns black, but what im tring to make, is a script that after all the parts inside BlueFolder are black, the ... games text wiil change to GAME OVER:

  local Status = game.ReplicatedStorage.GameStats.Status
local blue = workspace.BlueFolder

while true do

Status.Value = "Round 1 Starting!"
Status.Value = "3"
wait(0.8)
Status.Value = "2"
wait(0.8)
Status.Value = "1"
wait(0.8)

if  blue == BrickColor.new("Black") then

Status.Value = "Game over"
wait(1)

end

end


it just that i dont get it.. i tryed blue:GetChildren, but i cant figure it out

if in ur answer you can give me some info,thanks

BlueFolder is a folder that contains parts called Blue, that have a script in them , that when a character touches it, it turns Black. this is the script that each one has:

 part = script.Parent

part.Touched:connect(function()

part.BrickColor = BrickColor.new("Black")
wait(60 + 60)
part.BrickColor = BrickColor.new("Bright blue")
end)


1

You can iterate BlueFolder's children using a for loop and pairs/ipairs, then check if each child is black.

local Status = game.ReplicatedStorage.GameStats.Status
local blue = workspace.BlueFolder

local function allChildrenPartsAreBlack(parent): boolean
local parts: {BasePart} = {}
for _, child in ipairs(parent:GetChildren()) do
if child:IsA("BasePart") then -- if child is a part
table.insert(parts, child)
end
end

local blackParts: {BaseParts} = {}
for _, part in ipairs(parts) do
if part.BrickColor == BrickColor.new("Black") then -- if part is black
table.insert(blackParts, part)
end
end

return #blackParts == #parts -- returns a boolean (true/false) telling if number of black parts is the same as number of all children parts
end

while true do
Status.Value = "Round 1 Starting!"
Status.Value = "3"
Status.Value = "2"
Status.Value = "1"

local finished: boolean = false
repeat
finished = allChildrenPartsAreBlack(blue)
until finished -- when all parts are black

Status.Value = "GAME OVER"