Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
Gigaset39 111
1 year ago
Edited 1 year 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 answer

Log in to vote
1
Answered by 1 year ago

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!"
    task.wait(5)
    Status.Value = "3"
    task.wait(1)
    Status.Value = "2"
    task.wait(1)
    Status.Value = "1"
    task.wait(1)

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

    Status.Value = "GAME OVER"
    task.wait(5)
end
0
thankyou for ur answer, i m at a level in which i cant understand what it does exactly, but ima tring to figure it out. Gigaset39 111 — 1y
0
thisi s too hard.. cant you .. Gigaset39 111 — 1y
0
like.. make it more simple, i will ask ChatGPT. Gigaset39 111 — 1y
0
MAn, you gotta try it, ChatGPT know all!! even lua!! Gigaset39 111 — 1y
Ad

Answer this question