Getting the next child on GetChildren()?

As the title says, I want to know how to get the next child from a folder that contains several objects.
So far I’ve managed to get value, but I can’t clone the object using the value, or even parent it.

The code runs inside a click function:

local Itens = RP.Itens:GetChildren()
NextButton.MouseButton1Click:Connect(function()
	for i = 1, #Itens do
		local NextItem = Itens[i + 1]
        NextItem:Clone()
		NextItem.Parent = workspace.Item
     end
end

Any help will be appreciated

you missed an end after the for loop and a ) after the second end

Uh, yes, thanks for that, but still I cant get the next child.

If you want to get them all at once, then do:

local Items = RP.Items:GetChildren()

NextButton.MouseButton1Click:Connect(function()
	for _, child in ipairs(Items) do
		child:Clone()
		child.Parent = workspace.Item
	end
end)

If you want to get the items one by one, then do:

local Items = RP.Items:GetChildren()
local current = 1

NextButton.MouseButton1Click:Connect(function()
	if current > #Items then return end
	
	local child = Items[current]
	child:Clone()
	child.Parent = workspace.Item
	
	current += 1
end)

If you want to loop through items then do:

local Items = RP.Items:GetChildren()
local current = 1

NextButton.MouseButton1Click:Connect(function()
	local child = Items[current]
	child:Clone()
	child.Parent = workspace.Item
	
	current = current % #Items + 1
end)
3 Likes

Thanks for your time, I wanted to pick one by one, and this helped a lot!