Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would you union parts of the same name using UnionAsync?

Asked by 4 years ago

I have a function that does an afterimage effect, which instances new parts all named "Afterimage" which are the exact same size of each of the player's limbs. However, when im trying to use a while true loop in order to add transparency to the afterimage it adds transparency to only one part named Afterimage. So I was wondering if there is a way to union parts using UnionAsync on parts of the same name? The code concerned with is from lines 73 - 83

local rs = game:GetService("ReplicatedStorage")
local dash = rs:WaitForChild("Dash")
local TweenService = game:GetService("TweenService")

dash.OnServerEvent:Connect(function(player)
    local model = Instance.new("Model")
    model:Clone()
    model.Name = "WaveAndAfter"
    model.Parent = game.workspace

    local char = player.Character or player.CharacterAdded:Wait()

    local wave = script.Mesh:WaitForChild("Wave"):Clone() or script.Mesh:FindFirstChild("Wave"):Clone()
    wave.CFrame = char:WaitForChild("HumanoidRootPart").CFrame * CFrame.new(0, -3, 0)
    wave.Orientation = wave.Orientation + Vector3.new(-90, 0, 0)
    wave.Parent = model

    local fx = script["Electricity Shock Sound Effect"]:Clone()
    fx.Parent = wave
    fx:Play()

    local bolt1 = script.Folder:WaitForChild("Bolts2"):Clone() or script.Folder:FindFirstChild("Bolts2"):Clone()
    bolt1.Parent = wave

    local bolt2 = script.Folder:WaitForChild("Bolts3"):Clone() or script.Folder:FindFirstChild("Bolts3"):Clone()
    bolt2.Parent = wave

    local goal = {}
    goal.Size = wave.Size + Vector3.new(10,10,1)
    goal.Orientation = wave.Orientation + Vector3.new(0, 3600)
    goal.Transparency = 1
    local info = TweenInfo.new(2)
    local tween = TweenService:Create(wave,info,goal)
    tween:Play()

    for count, objectsInCharacter in ipairs(char:GetChildren()) do
        local afterimage = {}
        local head = {}
        if objectsInCharacter:IsA("MeshPart") or objectsInCharacter:IsA("Part") then
            if objectsInCharacter.Name ~= "HumanoidRootPart" and objectsInCharacter.Name ~= "Wave" and objectsInCharacter.Name ~= "Head" then
                afterimage = Instance.new("Part")
                afterimage.Size = objectsInCharacter.Size
                afterimage.Name = "Afterimage"
                afterimage:ClearAllChildren()
                afterimage.Transparency = 0.8
                afterimage.Color = Color3.fromRGB(10, 105, 220)
                afterimage.Material = "Glass"
                afterimage.CanCollide = false
                afterimage.Anchored = true
                afterimage.Massless = true
                afterimage.CFrame = objectsInCharacter.CFrame
                afterimage.Parent = game.Workspace

            elseif objectsInCharacter.Name == "Head" then
                head = script.Mesh.Head:Clone()
                head.Name = "AfterimageHead"
                head.Transparency = 0.8
                head.Color = Color3.fromRGB(10, 105, 220)
                head.Material = "Glass"
                head.Anchored = true
                head.CanCollide = false
                head.Massless = true
                head.CFrame = char.Head.CFrame
                head.Parent = game.Workspace
            end
        end
    end

    wait(0.3)
    local parts = game.Workspace:GetChildren()

    --this was my attempt to change the transparency of all parts. I found that if i used a while true loop it would still only affect one part instead of every part, so i decided to this. however, its still not the intended effect because it scans for one part, plays the for loop, then goes onto the next part.
    for i = 1, #parts do
        if parts[i].Name == "Afterimage" then
            parts[i].Transparency = parts[i].Transparency + 0.1
            wait(0.1)
            parts[i].Transparency = parts[i].Transparency + 0.1
            wait(0.1)
            parts[i].Transparency = parts[i].Transparency + 0.1
            wait(0.1)
            parts[i].Transparency = parts[i].Transparency + 0.1
        end
    end

    wait(2)

    bolt1:Destroy()
    bolt2:Destroy()

end)

Answer this question