So basically I have a model with a disco floor in it, all the parts inside of it except for one is called "DiscoFloor" the other is called "DiscoScreen", it only is lighting up "DiscoScreen" and I thought it would light up all of them, can someone fix this? Here is my code
01 | local floors = script.Parent:GetChildren() |
02 |
03 |
04 | for _,p in pairs (floors) do |
05 | while true do |
06 | if p:IsA( "Part" ) then |
07 | p.Color = Color 3. new(math.random(), math.random(), math.random()) |
08 | wait(. 5 ) |
09 | end |
10 | end |
11 | end |
I have a simple but effective way to fix it. 1st, name all the Discop Floor parts with a number at the end. (Part1, Part2, etc.) Place this Folder into game.Workspace
and name it 'GameScriptService'. Insert a script into it and name the script 'DiscoFloor'. Type the following:
01 | local num = 1 |
02 | local color 1 = Color 3. fromRGB( 0 , 255 , 0 ) |
03 | local color 2 = Color 3. fromRGB( 0 , 0 , 255 ) |
04 | while true do |
05 | local parts = game.Workspace.DiscoFloor:GetChildren() --change if you need to |
06 | for i = 1 ,#parts do |
07 | if num = = 1 then |
08 | if parts [ i ] .Name = = "Part1" or parts [ i ] .Name = = "Part3" then --Add more if necessary. This may not be the simplest way to do it, but it's the only way I know right now. |
09 | parts [ i ] .Color = color 1 |
10 | else |
11 | parts [ i ] .Color = color 2 |
12 | end |
13 | num = 2 |
14 | else |
15 | if parts [ i ] .Name = = "Part1" or parts [ i ] .Name = = "Part3" then --Add more if necessary. |
If this doesn't work, let me know and I'll try something else.
I know what caused your problem. You gave while true do
so it will forever go on looping the same brick. The script I gave below will change the color of every part and set it to random color every second.
Just rewrite the whole script as:
1 | while true do |
2 | for _,p in pairs (script.Parent:GetChildren()) do |
3 | if p:IsA( "Part" ) then |
4 | p.Color = BrickColor.random() |
5 | end |
6 | end |
7 | wait( 1 ) |
8 | end |
I hope that helps :D