#for loops

47 messages · Page 1 of 1 (latest)

left mulch
#

how can i make so that it gets every single children apart from the script to change it's color constantly?

#
for _,v in pairs(script.Parent:GetChildren()) do
    if v:IsA("BasePart") then
        local t = 0.3;
        while wait(1) do
            local hue = tick() % t/t
            local color = Color3.fromHSV(hue,0.5,0.5)
            v.Color = color
        end
    end
end
left mulch
umbral loom
#

yes because you are doing an infinite loop

#

while wait(1) do never ends

toxic monolith
#

turty wurty yo

#

can u help me

umbral loom
umbral loom
#
for _,v in pairs(script.Parent:GetChildren()) do
    if v:IsA("BasePart") then
        local t = 0.3;
        coroutine.wrap(function()
            while wait(1) do
                local hue = tick() % t/t
                local color = Color3.fromHSV(hue,0.5,0.5)
                v.Color = color
            end
        end)()
    end
end```
left mulch
#

like all of the colors u see here should be the same

umbral loom
#

alternatively, since coroutines are rather complicated, you could loop, add each part to a table, and then loop through the table in a while loop

umbral loom
#

my second solution should fix that

left mulch
#

cuz idk how to do that since im new

umbral loom
#

something like this i think? ```lua
local foundParts = {}

for _,v in pairs(script.Parent:GetChildren()) do
if v:IsA("BasePart") then
table.insert(foundParts, {["Part"] = v, ["Time"] = 0.3})
end
end

while wait(1) do
for _, v in pairs(foundParts) do
local hue = tick() % v["Time"]/v["Time"]
local color = Color3.fromHSV(hue,0.5,0.5)
v["Part"].Color = color
end
end```

#

tbh im not very good with tables though, so that may not be right

left mulch
#

o wow that works and this is way beyond me

umbral loom
#

it works?

left mulch
#

yes perfectly

umbral loom
#

wow

left mulch
#

u are a great scripter

umbral loom
#

i actually didnt expect that to work lmao

left mulch
#

u also made that one fast

umbral loom
left mulch
#

since i just started scripting and i really wanna learn

#

and also it only selects like 5 colors

umbral loom
#

i'll go step by step.

Firstly, we create a "table" called foundParts. This will store all of the parts that we find as well as the time value that is associated with that part.
Then we do the loop that you had before, going through each of the children.
Then we check to see if the child is a BasePart (same as you had before).
Then we grab the foundParts table that we made earlier, and insert v and the 0.3 into the table, named Part and Time respectively.
Once we have inserted all of the parts into the table, we do our while wait(1) loop.
Every time the loop runs, we do another loop, going through all of the data that we inserted into foundParts.
-- The rest is just your code, but subsituting t for v["Time"] (aka getting that Time attribute that we inserted previously), and substituting v for v["Part"] (aka getting the Part attribute that we inserted earlier --

gleaming zephyr
umbral loom
#

actually

#

thats true

#

that also means it wouldnt need a table

#

i dont know why i didnt think of that

gleaming zephyr
#

💀 sometimes the answer is the simplest

umbral loom
#

fr

#

see i usually dont think of the simple solutions. my brain instantly jumps to complex solutions

left mulch
#

and also how do i make the rgb with all the colors? i mean it only takes around 5 colors

umbral loom
#

well

#

v["Time"]/v["Time"] is always gonna be 1 right?

#

well anyways, you have limited colours because your wait increment is always 1

#

if you change wait(1) to wait() then it wont be limited

#

and if you want to make it crazier you can change the saturation and value

#

also, i was able to massively simplify your script lua while wait() do for _,v in pairs(script.Parent:GetChildren()) do if v:IsA("BasePart") then local hue = tick() % 1 local color = Color3.fromHSV(hue, 0.5, 0.5) v.Color = color end end end