What does attempt to call nil value mean?

I get the error “attempt to call a nil value”

           local x = script.parent.x.value
	       local y = script.parent.y.value
	       local z = script.parent.z.value
           local clo = it:Clone()
            clo.Parent = it.Parent
			print("Parented")
			it:Destroy()
			print("Destroyed")
			print(clo.Parent) 
			clo:MoveTo(Vector3.New(x,y,z)) --in this line (error. Line 35)

Anyone know why I am getting this error?

What line are you getting the error on? Please include line numbers and a screenshot of output.

Screenshot 2022-03-29 at 22.26.15

This error is kind of self explanatory, you’re trying to call the function :MoveTo() which does not exist in clo. What type of instance is clo? It must be a Model if you’re trying to call :MoveTo()

Yes. Clo is a model. Do I need to create the function moveto() myself?

Do you mind sharing the whole code?


script.Parent.Touched:Connect(function(hit)
	local obj 
	local huma = hit.Parent.Name
	--local va = script.Parent.Valu.Value
	local x = script.parent.x.value
	local y = script.parent.y.value
	local z = script.parent.z.value
	wait()
	print(huma)
	print(x)
	print(y)
	print(z)
	wait()
	for i,v in pairs(game.Workspace.kit.Tycoons:GetChildren()) do
		print(i)
		print(v)
		print(v.Owner.Value)
		local t = v.Owner.Value
		wait()
		print(t.Name)
		if v.Owner.Value.Name == huma then
			local it = v.PurchasedObjects.Up
			print("Found it here")
			local clo = it:Clone()
			print("Cloned")
			clo.Parent = it.Parent
			print("Parented")
			it:Destroy()
			print("Destroyed")
			print(clo.Parent)
			print("ABOVE IS THE PARENT")
			clo:MoveTo(Vector3.New(x,y,z))
			--vector3.new(x,y,z)
			print("Positioned")
		end
	end
end)

1 Like

Add this line in like this:

clo.Parent = it.Parent
it:Destroy()
print(clo, typeof(clo), clo.ClassName) -- Add this
clo:MoveTo(Vector3.New(x,y,z))

Oh, you’re calling Vector3.New() not Vector3.new()

It’s case sensitive.

2 Likes

Ah, lol. It runs now, thank you.