Random:clone() and random:Clone() position

Hi, I have a problem regarding this and that is that the MaterialRandom part is not cloned, and I do not know how to move the cloning position to the position of an object

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local FolderMaterial = ReplicatedStorage:WaitForChild("Materiales"):WaitForChild("Cargarmateria")
local Tronco = FolderMaterial:FindFirstChild("Tronco")
local RamaGrande = FolderMaterial:FindFirstChild("RamaGrande")

local items = {Tronco, RamaGrande}
			
local AmounMaterial = math.random(1, 5)
local MaterialRandom = items[math.random(AmounMaterial, AmounMaterial)]:Clone()
			
MaterialRandom.Parent = workspace.SistemaDeTalado
MaterialRandom.Position = script.Parent.Parent.Hojas.Position

for this script, it will work 2/5 times. doing

items[--[[number]]]

will be asking for a slot in the table called “items” and there are only 2 items listed. Assuming the “AmounMaterial” variable is for how many times it’ll be cloned, you would do a repeat or a for loop.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local FolderMaterial = ReplicatedStorage:WaitForChild("Materiales"):WaitForChild("Cargarmateria")
local Tronco = FolderMaterial:FindFirstChild("Tronco")
local RamaGrande = FolderMaterial:FindFirstChild("RamaGrande")

local items = {Tronco, RamaGrande}
			
local AmounMaterial = math.random(1, 5)

for i = 1, AmounMaterial do --repeat it by the amount of the materials.
local MaterialRandom = items[math.random(1, #items)]:Clone() --change it to math.random(1,#items) so it will always get a item instead of 2/5 of the time
			
MaterialRandom.Parent = workspace.SistemaDeTalado
MaterialRandom.Position = script.Parent.Parent.Hojas.Position
end
1 Like