I have an model where all descendants called Part need to slowly shift color, here's the code I already have:
01 | items = { } |
02 |
03 | for index, descendant in pairs (script.Parent.Model:GetDescendants()) do |
04 | if descendant.Name = = "Part" then |
05 | table.insert(items, descendant) |
06 | end |
07 | end |
08 |
09 | while true do |
10 | for i, v in items do |
11 | -- What do I do now? |
12 | end |
13 |
14 | wait(math.random( 0.95 , 1.05 )) -- Stay as solid color for a very short while |
15 | end |
I'd rather have my game run nice and smooth, but if no one knows how to make this code also smooth I'll just use the best other code I can find.
Here is the gist
01 | local tween = function (Object, Changes) |
02 | local Info = TweenInfo.new( |
03 | . 5 , --Time to do the tween |
04 | Enum.EasingStyle.Back, -- Style |
05 | Enum.EasingDirection.Out, -- Direction |
06 | 0 , -- number of repeats |
07 | false , -- reverts back to normal |
08 | 0 -- Delay |
09 | ) |
10 | local TweenService = game:GetService( "TweenService" ) |
11 | local Action = TweenService:Create(Object, Info, Changes) |
12 | return Action |
13 | end |
14 |
15 |
16 | while true do |
17 | local Action = tween(script.Parent, { Color = Color 3. fromRGB(math.random( 0 , 255 ), math.random( 0 , 255 ), math.random( 0 , 255 )) } ) |
18 | Action:Play() |
19 | Action.Completed:Wait() |
20 | end |
Put this in a brick
01 | local colors = { BrickColor.new( "Steel blue" ).Color, |
02 | BrickColor.new( "Bright violet" ).Color, |
03 | BrickColor.new( "Magenta" ).Color, |
04 | BrickColor.new( "Neon orange" ).Color, |
05 | BrickColor.new( "Bright yellow" ).Color, |
06 | BrickColor.new( "Lime green" ).Color, |
07 | BrickColor.new( "Toothpaste" ).Color } -- the colors table, you change change them. |
08 |
09 | local tweenService = game:GetService( "TweenService" ) |
10 |
11 | script.parent.Material = ( "Neon" ) --The Mateiral |
12 |
13 | function ColorChange(colorToChangeTo) --color change function |
14 |
15 | local time = 3 --Set this to the time |
Nvm, I found a solution myself, it might now be the smoothest but I'm fine with it.
01 | local items = { } |
02 |
03 | for index, descendant in pairs (script.Parent.Model:GetDescendants()) do |
04 | if descendant.Name = = "Part" then |
05 | table.insert(items, descendant) |
06 | end |
07 | end |
08 |
09 | function positify(val) |
10 | if val < 0 then |
11 | return -val |
12 | else |
13 | return val |
14 | end |
15 | end |