| |
|
|
| 02 Aug 2014 10:22 AM |
local objects = {}
while wait() do if c.BrickColor == BrickColor.Green() and not objects[c] then print("Puzzle completed!") objects[c] = true c.BrickColor = BrickColor.Black() end end if #children == #objects then for k, _ in pairs(objects) do if k.BrickColor == BrickColor.Green() then print("Puzzle completed!") k.BrickColor = BrickColor.Black() end end end end |
|
|
| Report Abuse |
|
|
|
| 02 Aug 2014 10:23 AM |
local objects = {}
while wait() do for _, c in pairs(objects) do if c.BrickColor == BrickColor.Green() and not objects[c] then print("Puzzle completed!") objects[c] = true c.BrickColor = BrickColor.Black() end end if #children == #objects then for k, _ in pairs(objects) do if k.BrickColor == BrickColor.Green() then print("Puzzle completed!") k.BrickColor = BrickColor.Black() end end end end |
|
|
| Report Abuse |
|
|
|
| 02 Aug 2014 10:24 AM |
woops
Original Post Re: Check if all children in model are green? Posted by duelingwarlord on 08-02-2014 10:23 AM
local objects = {}
while wait() do for _, c in pairs(children) do if c.BrickColor == BrickColor.Green() and not objects[c] then objects[c] = true end end if #children == #objects then for k, _ in pairs(objects) do if k.BrickColor == BrickColor.Green() then print("Puzzle completed!") k.BrickColor = BrickColor.Black() end end end end |
|
|
| Report Abuse |
|
|
| |
|
| |
|
DukeCow
|
  |
| Joined: 20 Nov 2010 |
| Total Posts: 13176 |
|
|
| 02 Aug 2014 11:26 AM |
while wait() do children = (model name):GetChildren for i,v in pairs(children) do if v.BrickColor = BrickColor.new("Green") then print("Puzzle completed!") wait(1) v.BrickColor = BrickColor.new("Black") end end end |
|
|
| Report Abuse |
|
|
Jammer622
|
  |
| Joined: 19 Nov 2008 |
| Total Posts: 1739 |
|
|
| 02 Aug 2014 11:30 AM |
while wait() do isGreen = true for _, c in pairs(children) do if c.BrickColor ~= BrickColor.Green() then isGreen = false end end if isGreen then print("Puzzle completed!") for _, c in pairs(children) do c.BrickColor = BrickColor.Black() end end end
That should work for you. Let me know if there's any other problems. |
|
|
| Report Abuse |
|
|
| |
|
Jammer622
|
  |
| Joined: 19 Nov 2008 |
| Total Posts: 1739 |
|
|
| 02 Aug 2014 12:25 PM |
| What mine does is start off saying that they are all green, and then if it notices that any arent, then it says that they aren't all green. It's an innocent until proven guilty function, instead of guilty until innocent where if a single one is green then it still counts. Did you try mine before you said they werent working? |
|
|
| Report Abuse |
|
|
BooneHEAD
|
  |
| Joined: 09 Oct 2011 |
| Total Posts: 125099 |
|
| |
|
|
| 02 Aug 2014 12:32 PM |
You can do it any of those other ways, or this way, actually there's so many ways.
local function Check(Obj) local Accepted = {} local Declined = {} for _,v in pairs(Obj:GetChildren()) do if v:IsA("BasePart") then if v.BrickColor == BrickColor.new("Bright green") then table.insert(Accepted, v) else table.insert(Declined, v) end end Check(v) end return #Accepted == #Accepted - #Declined end
if Check(...) then print("Go for launch") else print("No go for launch") end |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 02 Aug 2014 01:09 PM |
| Jammer's way is probably the most efficient here. |
|
|
| Report Abuse |
|
|
Jammer622
|
  |
| Joined: 19 Nov 2008 |
| Total Posts: 1739 |
|
|
| 02 Aug 2014 01:10 PM |
| Well, it'd probably be a little better if wait() in the first line was more spacey. It's scanning them at top speed in mine :/ |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 02 Aug 2014 01:13 PM |
| Add a break after making isGreen = false. No need for more useless iterations |
|
|
| Report Abuse |
|
|
Jammer622
|
  |
| Joined: 19 Nov 2008 |
| Total Posts: 1739 |
|
|
| 02 Aug 2014 01:18 PM |
| I'd imagine it could be done multiple times, since it resets to black afterwards. |
|
|
| Report Abuse |
|
|