Attempt to call nil value when cloning with :GetChildren()

Hello, I’m trying to clone the item within the selection for my vending machine, however, I get a nil value error. Any help is appreciated.

local Tools = script.Parent.Tools
local Selections = script.Parent.Selections
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local enter = script.Parent.Screen.SurfaceGui.Select.Enter
local cancel = script.Parent.Screen.SurfaceGui.Select.Cancel

local UIinfo = TweenInfo.new(
	0.1, --Time
	Enum.EasingStyle.Sine, -- Style of door open animation
	Enum.EasingDirection.InOut, -- Direction of easing.
	0, -- Repeat count.
	false, -- Will it reverse?
	0 -- The delay time.
)


if game.IsLoaded then
	Tools.Parent = ReplicatedStorage
end


local result = ""

for i, v in pairs(script.Parent.Screen.SurfaceGui.Select:GetChildren()) do
	if not v:IsA("TextButton") then continue end 
	local uithickness = v.UIStroke
	local tweenenter = TweenService:Create(uithickness, UIinfo, {Thickness = 4})
	local tweenleave = TweenService:Create(uithickness, UIinfo, {Thickness = 2})
	v.MouseEnter:Connect(function()
		tweenleave:Cancel()
		tweenenter:Play()
	end)
	v.MouseLeave:Connect(function()
		tweenenter:Cancel()
		tweenleave:Play()
	end) 
	v.MouseButton1Down:Connect(function()
		if v.Name == "Enter" then 
			print(result) 
			if Selections:FindFirstChild(result) then
				print("Found".. result)
				-- Clones the item
				
				
				
				
				
				-- Where I'm trying to clone
				local item = Selections:FindFirstChild(result).Item:GetChildren()
				item:Clone()
				item.Position = result.Dropper
				
				
				
				
				
				
				
					elseif not Selections:FindFirstChild(result) then
				print("Not found!")
				script.Parent.Screen.SurfaceGui.Text.SelectionNo.Text = "Item does not exist."
				wait(2)
				script.Parent.Screen.SurfaceGui.Text.SelectionNo.Text = result
					end
		
		elseif v.Name == "Cancel" then 
			result = ""
			script.Parent.Screen.SurfaceGui.Text.SelectionNo.Text = "__"
		else
			result ..= v.Text
			
			script.Parent.Screen.SurfaceGui.Text.SelectionNo.Text = result
		end
	end)
end

The instance method “:GetChildren()” returns an array of instances which are the immediate children of the instance through/on which the method was called, if you want to clone those children then you’d first need to loop over the array and call the instance method “:Clone()” on each child instance iterated over, similarly, instead of cloning each child of some instance you could instead clone the instance itself (which approach you decide to use is ultimately up to you).

--iterating over each child in the array returned by getchildren()

local selection = Selections:FindFirstChild(result)
if selection then
	local item = selection:FindFirstChild("Item")
	if item then
		local items = item:GetChildren()
		for _, child in ipairs(item:GetChildren()) do
			child:Clone()
			child.Position = result.Dropper
		end
	end
end
--cloning the instance itself instead of getting its children

local selection = Selections:FindFirstChild(result)
if selection then
	local item = selection:FindFirstChild("Item")
	if item then
		item:Clone()
	end
end

Hi, I got back this error Workspace.Vending.Main_Code:54: invalid argument #3 (Vector3 expected, got Instance)

Change this to child.Position = result.Dropper.Position. If this helps, solution still goes to @Forummer.

result.Dropper

If this is a reference to a BasePart instance then you’ll need to index its “Position” property as the previous user suggested. I wasn’t aware of what it was.

Thank you @Forummer and @NeoBuilds , this worked!