Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Vector3 Expected, got nil?

So, I'm trying to make a model face a certain direction depending on what way you're facing, but when I try setting it to look at a part, it comes up nil?

bad argument #1 to 'new' (Vector3 expected, got nil)
local part = script.Parent.Model:GetChildren()
local open1 = script.Parent.Sens -- The part that will turn to face Part2
local open2 = script.Parent.Sens2
local origin = script.Parent.Sens3
local sensor1 = script.Parent.Sensor1
local sensor2 = script.Parent.Sensor2
open = false

--Opening from interior
function opene()
	if open == false then
		open = true
		--ERRORS HERE--
		part.BodyGyro.cframe = CFrame.new(part.Position, open2.Position)
		wait(5)
		part.BodyGyro.cframe = CFrame.new(part.Position, origin.Position)
		--ERRORS HERE--
		open = false
	end
end

--Opening from exterior
function openi()
	if open == false then
		open = true
		--ERRORS HERE--
		part.BodyGyro.cframe = CFrame.new(part.Position, open1.Position)
		wait(5)
		part.BodyGyro.cframe = CFrame.new(part.Position, origin.Position)
		--ERRORS HERE--
		open = false
	end
end

sensor1.Touched:connect(opene)
sensor2.Touched:connect(openi)

1 answer

✓ Accepted answer
local part = script.Parent.Model:GetChildren()

part is a list. It doesn't have a position.

You have to give CFrame a legit Position, so you obviously need a legit Part. Since part is currently just a list of the children of a model, I'm not sure which one you actually want it to face, so I'll just let you put that in. But the point is, you need a specific object.

This discussion is preserved as it was. New answers, comments, and votes are closed.