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

How can I get my for loop to play more than once?

Asked by 3 years ago

I'm running to i,v for loop on a while true do loop so that it continuously plays, but once I get to the second play it doesn't work. I tried using i = num1,num2 loops but I could never actually get all the items in my folder. Any help would be appreciated.

local TweenService = game:GetService("TweenService")
local IceShards = game.ReplicatedStorage["Aeacus-Parts"].IceShards

local randoFuncs = {
    function(input)
        print("Icalance")
        local ShardChildren = IceShards:GetChildren()
        for i,v in pairs(ShardChildren) do
            v:Clone()
            v.Anchored = true
            v.Parent = workspace
            local tweenInfo1 = TweenInfo.new(0.1,Enum.EasingStyle.Cubic,Enum.EasingDirection.In,0,false)
            local tween1 = TweenService:Create(v,tweenInfo1,{Size = Vector3.new(18.796, 18.5, 5.75)})
            tween1:Play()
            wait(0.1)
            v.Anchored = false
            local bv = Instance.new("BodyVelocity")
            bv.Parent = v
            bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
            bv.Velocity = Vector3.new(0,-40,0)
            --
            wait(0.1)
        end
    end
}

while true do
    local torso = findTarget()
    if torso then
        local func = randoFuncs[math.random(1, #randoFuncs)]
        func()
    end
    wait(5)
end

Regards, Bl_ueHistory

2 answers

Log in to vote
1
Answered by 3 years ago

At line 9, in your snippet of code. You set the parent of the item you were cloning, but not the clone itself!

Here is what you should do when cloning:

local Clone = v:Clone()
Clone.Parent = workspace
-- rest of your code

This might not be the solution to your problem. But it is a huge issue.

Ad
Log in to vote
0
Answered by
Simxzn 2
3 years ago

I'm not sure, but you can try to wrap the function in a couroutine function. Like this:

coroutine.wrap(function()
while true do
--script
wait(5)
end
end)()

Answer this question