Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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.

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)()

This discussion is preserved as it was. New answers, comments, and votes are closed.