generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Check if all children in model are green?

Previous Thread :: Next Thread 
Badfitz100 is not online. Badfitz100
Joined: 03 Nov 2010
Total Posts: 12591
02 Aug 2014 10:16 AM
[ Content Deleted ]
Report Abuse
Duelingwarlord is not online. Duelingwarlord
Joined: 15 Feb 2010
Total Posts: 22333
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
Duelingwarlord is not online. Duelingwarlord
Joined: 15 Feb 2010
Total Posts: 22333
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
Duelingwarlord is not online. Duelingwarlord
Joined: 15 Feb 2010
Total Posts: 22333
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
Badfitz100 is not online. Badfitz100
Joined: 03 Nov 2010
Total Posts: 12591
02 Aug 2014 10:32 AM
[ Content Deleted ]
Report Abuse
Badfitz100 is not online. Badfitz100
Joined: 03 Nov 2010
Total Posts: 12591
02 Aug 2014 10:37 AM
[ Content Deleted ]
Report Abuse
DukeCow is not online. 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 is not online. 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
Badfitz100 is not online. Badfitz100
Joined: 03 Nov 2010
Total Posts: 12591
02 Aug 2014 12:18 PM
[ Content Deleted ]
Report Abuse
Jammer622 is not online. 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 is not online. BooneHEAD
Joined: 09 Oct 2011
Total Posts: 125099
02 Aug 2014 12:31 PM
must be green.
Report Abuse
MarkAntonius is not online. MarkAntonius
Joined: 14 Sep 2013
Total Posts: 27
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 is not online. 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 is not online. 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 is not online. 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 is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image