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

Tween All Children in For Loop (with animation)?

Asked by 2 years ago
Edited 2 years ago

Hi! I have this script that plays an Animation and gives you a tool. The tool you acquire is from a crate, and I want to tween some cool fading thing. However, I could've used unions, but it was too glitchy and left some parts. So, I tried using a for loop to gather every part in my crate and do the fading thing. I failed because the Animation would run in the for loop, and I had to wait for it to gather every part I wanted. How would I go about this? You don't need to give me code. Just explain and answer for me to put it in my code. Here's the code!

local proximityPrompt = script.Parent.Special2.ProximityPrompt
local RS = game:GetService("ReplicatedStorage")

proximityPrompt.Triggered:Connect(function(plr)
    local char = plr.Character or plr.CharacterAdded:Wait()
    local hum = char:WaitForChild("Humanoid")
    local randomArray = {RS:WaitForChild("Tool"), RS:WaitForChild("Tool2"), RS:WaitForChild("Tool3"), RS:WaitForChild("Tool4"), RS:WaitForChild("Tool5")}
    local randomIndex = math.random(1,#randomArray)
    local randomTool = randomArray[randomIndex]
    local toolClone = randomTool:Clone()
    local deathAnim = hum:LoadAnimation(script.DeathAnim)
    local debounce = true

    for i,v in pairs(plr.Backpack:GetChildren()) do
        if v.Name == randomTool.Name then
            debounce = false
            print(randomTool.Name)
        end
    end
    if debounce == true then
        for i,v in pairs(script.Parent:GetChildren()) do
            if v.Name == "Part" then

        local Info = TweenInfo.new(1.5)
        local Tween1 = game:GetService("TweenService"):Create(v,Info,{Transparency=0})
        local Tween2 = game:GetService("TweenService"):Create(v,Info,{Transparency=1})
        deathAnim:Play()
        wait(1.5)
        Tween2:Play()
        proximityPrompt.Enabled = false
        v.CanCollide = false
        script.Parent.Spawner.Attachment.ParticleEmitter.Enabled = true
        toolClone.Parent = plr.Backpack
        wait(5)
        Tween1:Play()
        v.CanCollide = true
        script.Parent.Spawner.Attachment.ParticleEmitter.Enabled = false
        proximityPrompt.Enabled = true
            end
        end
    end
    debounce = true
end)

1 answer

Log in to vote
0
Answered by 2 years ago

Try using delay instead of wait:

delay(time, function()
    -- Your code
end)
0
Can you explain what that delay function is/does? rizdoesntlikeyou 0 — 2y
Ad

Answer this question