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