#for loops
47 messages · Page 1 of 1 (latest)
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
this only works to one part in a model with 10+ parts
what i would do in this situation is use a coroutine probably
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```
it somehow works but wierd
like all of the colors u see here should be the same
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
ah yea ik why
my second solution should fix that
so what exactly should i change in what u gave me?
cuz idk how to do that since im new
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
o wow that works and this is way beyond me
it works?
yes perfectly
wow
u are a great scripter
i actually didnt expect that to work lmao
u also made that one fast
i can try and explain it to you if you want?
that would be great
since i just started scripting and i really wanna learn
and also it only selects like 5 colors
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 --
could you not have just wrapped the entire for loop into a while true loop instead of using a coroutine wrap??
actually
thats true
that also means it wouldnt need a table
i dont know why i didnt think of that
💀 sometimes the answer is the simplest
fr
see i usually dont think of the simple solutions. my brain instantly jumps to complex solutions
thanks again
and also how do i make the rgb with all the colors? i mean it only takes around 5 colors
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