Attempt to index number with "Dot"?

Its the first time I’m using :dot() and its giving me this error attempt to index number with 'Dot'. I’m trying to make a function that checks if the player has the same or similar orientation as the specific part, buuuut it seems I’m doing something wrong but I don’t know what, any suggestions???

whole code:

local function angleBetweenVectors(vec1, vec2)
	return math.deg(math.acos(vec1:Dot(vec2) / (vec1.Magnitude * vec2.Magnitude)))
end

How/where are you calling this function?

because I just tested it out and it seems to be working fine, maybe there’s something wrong with your call to the function?

2 Likes

Inside a serverscript in serverscriptservice

Yes, but where do you call the function ,like where do you do -

local function angleBetweenVectors(vec1, vec2)
	return math.deg(math.acos(vec1:Dot(vec2) / (vec1.Magnitude * vec2.Magnitude)))
end

angleBetweenVectors(vecA,vecB)

did you provide 2 valid arguments?

1 Like

Oooooh sorry I misread that, I call it here:


	Detector.Touched:Connect(function(hit)
		local playerOrientation = player.Character.HumanoidRootPart.CFrame:ToOrientation()
		local partOrientation = Detector.CFrame:ToOrientation()
		local angleBetween = angleBetweenVectors(partOrientation, playerOrientation)
		
		if angleBetween <= 30 then

1.It’d be better to get the entire code [relevant]
2.Try to print playerOrientation and partOrientation

1 Like

CFrame:ToOrientation() returns 3 numbers.

Try:

local x0, y0, z0 = player.Character.HumanoidRootPart.CFrame:ToOrientation()
local playerOrientation = Vector3.new(x0, y0, z0)

local x1, y1, z1 = Detector.CFrame:ToOrientation()
local partOrientation = Vector3.new(x1, y1, z1)

local angleBetween = angleBetweenVectors(playerOrientation, partOrientation)

Edit:

Alternatively, you can just pass the ToOrientation into a Vector3.new() like this:

local playerOrientation = Vector3.new(player.Character.HumanoidRootPart.CFrame:ToOrientation())
local partOrientation = Vector3.new(Detector.CFrame:ToOrientation())

local angleBetween = angleBetweenVectors(playerOrientation, partOrientation)
2 Likes

image
I exported this to a seperate script and it still won’t execute :dot()

It prints now and it doesn’t show any error, Thanks!!!