What do you want to achieve?
I am trying to create a for loop that gradually increases the colour property of multiple parts from an array created by :GetDescendants()
I am wanting to have each part modified at the same time, so that if I implement a wait() the wait affects the loop speed rather than the delay between each part modification
What is the issue?
I dont know how I would use a for loop in such a way as to modify multiple parts at the same time.
What solutions have you tried so far?
I’ve looked for tutorials on youtube and searched generally on the web for any help but to no avail. DevForums is the next solution to my problem, hopefully!
My code so far to help:
local function LightsOn(WindowName, R, G, B)
local TrainParts = script.Parent:GetDescendants() --This creates an array of all parts within the main train model.
for _, C in ipairs(TrainParts) do
if C.Name == WindowName then
C.Color = Color3.fromRGB(R,G,B)
end
end
end
WindowName is the name of the part(s) that should be modified
R, G and B are 3 separate int values that let the script know the desired RGB colour to set the parts to, however I would like to fade these in gradually via the loop however I’m not sure how to do that with this loop that filters out the correct parts, with a for loop with modifiable numbers I could do that, however I am a bit clueless as to what to do here!
I am looking for help in creating a for loop that does this, and not a tween as I unfortunately dont understand tweenservice beyond the slightest.
Please do something like this: (this script assumes you have already defined the variables)
local parts = group:GetDescendants()
local function LightsOn(WindowName, R, G, B)
for _, part in pairs(parts) do
TweenService:Create(part,tweeninfo,{Color3 = Colour3.fromRGB(R,G,B)}):Play()
end
end
I see, however how would I manage to do this with my 3 separate R, G and B values? I presume that I would plug those into the colour value as R, G, B and that would work?
Use coroutines. They allow you asyncronously execute code.
local function LightsOn(WindowName, R, G, B)
local TrainParts = script.Parent:GetDescendants() --This creates an array of all parts within the main train model.
for _, C in ipairs(TrainParts) do
coroutine.resume(coroutine.create(function()
if C.Name == WindowName then
C.Color = Color3.fromRGB(R,G,B)
end
end))
end
end
EDIT: Sorry for the formatting, your formatting is weird so it messed mine up
Well, first define the variable by using game:GetService("TweenService"), then make a new tweeninfo. For more info, please use TweenInfo and TweenService
I have no clue if this is what you are looking for?
function ColorGradual(R, G, B)
local Parts = script.Parent:GetDescendants()
for Count = 1, 100 do
wait(0.01)
for index, value in pairs(Parts) do
value.Color = Color3.fromRGB(R+Count, G+Count, B+Count)
end
end
end
the R, G and B values are the variables that control the values for Red, Green and Blue for modifying the Colour3 property. I am looking to fade the values up from 0 to the values set by the R, G and B variables. This would just add 100 to the values equally.
For example, 255,255,0 would be set as:
R = 255
G = 255
B = 0
What I am looking to achieve is to fade these values up, and it should be noted that the values obviously wont be as simple as these, so I would need to divide the values and then multiply them by the count during the loop, however I cant quite think of how the logic would work for that
Yeah those sources dont seem to explain how the properties work in practice very well unlike other API pages, I dont really get them right now lol. Might have a test around with the functions later
I dont understand how I would use the TweenInfo functions to modify the tween. There’s no example code unlike other API sources. I’m more familiar with for loops and previous attempts to understand the tweenservice haven’t gone very well lol, just leaves me scratching my head
Tweening is used for transitions. For example, if you wanted to change a red brick’s colour from red to blue and you wanted it to smoothly transition instead of just happening, you’d tween it.
yeah I understand what tweening is used for but I dont get how its used to make that happen
I’ve always used for loops to gradually change a colour property