Hello DevForum. As of yesterday I was dealing with a slight issue when I was trying to tween multiple versions of the same thing. I am currently doing a cutscene, and I’m attempting a loop to get this specific attachment, then get the children of that attachment which have multiple different variants of particleemitters. I first attempted to specifically look for the name “AuraHolder”, but it was never actually happening, because they were in a table.
After I did table.find, it still didn’t work, so I took another dev’s suggestion and it only worked for one specific body part, and it only tweens one singular particleemitter which was what I was avoiding.
So, I’ll send the script, and hopefully get assistance. Thank you for your time.
if AURAAAAA.Parent == workspace then
for i, v in pairs(arg[3].Parent:GetChildren()) do
if v:FindFirstChild("AuraHolder") then
print("yo bro")
for i, auraemitters in pairs(v:FindFirstChild("AuraHolder"):GetChildren()) do
print(i)
print(v:FindFirstChild("AuraHolder"):GetChildren())
for i = 0, 0.5, wait() / Time do
auraemitters[i+1].Color = ColorSequence.new(auraemitters[i+1].Color.Keypoints[1].Value:lerp(Color3.new(255,255, 255), i))
wait()
end
end
end
--[[ local secondaryaura = v:FindFirstChildWhichIsA("ParticleEmitter")
for i = 0, 1, wait() / Time do
secondaryaura.Color = ColorSequence.new(secondaryaura.Color.Keypoints[1].Value:lerp(Color3.new(255,255, 255), i))
wait()
end
]]
end
end
end)
end)
end)
P.S- If you need a video showing the issue, I can get one quickly just say it.
arg[3] is specifically just whatever I chose. In this case, it’s LeftHand, but I should change it to Character. What is the difference between GetDescendants and GetChildren in this case? Checking the API, it still sends an Array regardless.
GetChildren only returns the “children” of an object. GetDescendants returns all “descendants” of an object.
Think of a family tree. The grandparent has children. The children, who are adults, have their own children as well.
Grandparent == Object
> Parent 1 == Child of Grandparent
> Son == Descendant of Grandparent, Child of Parent 1
> Parent 2 == Child of Grandparent
> Daughter == Descendant of Grandparent, Child of Parent 2
> Son == Descendant of Grandparent, Child of Parent 2
The bigger the family tree, the more descendants the grandparent has.
So, through GetDescendants, it’s saving me another loop, and I can directly do “if v.Name = “AuraHolder””, but I still would have the issue of getting getting stuck with one singular “AuraHolder” no? Along with trying to get it in a table.
task.spawn(function()
for i = 0, 0.5, wait() / Time do
auraemitters[i+1].Color = ColorSequence.new(auraemitters[i+1].Color.Keypoints[1].Value:lerp(Color3.new(255,255, 255), i))
wait()
end
end)
This would’ve been less messy if TweenService can animate sequences.
The issue still stands, it’ll only edit one of each. I want to edit all of these "AuraHolder"s children, but findfirstchild scopes me into a singular one. What would I do to it fix up?
AURAAAAA.Changed:Connect(function()
if AURAAAAA.Parent == workspace then
for i, v in pairs(arg[3]:GetDescendants()) do
print(v)
if v:FindFirstChild("AuraHolder") then
print("yo bro")
task.spawn(function()
for i, auraemitters in pairs(v.AuraHolder:GetChildren()) do
for i = 0, 0.5, wait() / Time do
auraemitters.LightEmission = 1
auraemitters.Color = ColorSequence.new(auraemitters.Color.Keypoints[1].Value:lerp(Color3.new(255,255, 255), i))
wait()
end
end
end)
end
local secondaryaura = v:FindFirstChildWhichIsA("ParticleEmitter")
for i = 0, 1, wait() / Time do
secondaryaura.LightEmission = 1
secondaryaura.Color = ColorSequence.new(secondaryaura.Color.Keypoints[1].Value:lerp(Color3.new(255,255, 255), i))
wait()
end
end
end
end)
end)
You’ve got two loops wait()ing on the same function. One was already corrected earlier, however I also corrected that correction too with the task.spawn part.
These wait()s will pause the main function from continuing its other processes. If you want the main function to run without pausing, do the wait()ing work on a separate thread through task.spawn.
Here, this should work:
-- Code made much more readable by reducing nesting of if statements.
AURAAAAA.Changed:Connect(function()
if not (AURAAAAA.Parent == workspace) then
return
end
for _, v in arg[3]:GetDescendants() do
if not (v.Name == "AuraHolder") then
continue
end
local secondaryaura = v:FindFirstChildWhichIsA("ParticleEmitter")
for _, auraemitters in v.AuraHolder:GetChildren() do
task.spawn(function()
for i = 0, 0.5, task.wait() / Time do
auraemitters.LightEmission = 1
auraemitters.Color = ColorSequence.new(auraemitters.Color.Keypoints[1].Value:lerp(Color3.new(255,255, 255), i))
task.wait()
end
end)
end
if not secondaryaura then
continue
end
task.spawn(function()
for i = 0, 1, task.wait() / Time do
secondaryaura.LightEmission = 1
secondaryaura.Color = ColorSequence.new(secondaryaura.Color.Keypoints[1].Value:lerp(Color3.new(255,255, 255), i))
task.wait()
end
end)
end
end)