Vector 3 Dot not working

I have this portion of my script where I’m trying to get the vector3 dot relative to 2 players root part. and when I print it it returns a weird value
image

local function getcontest(player, type_)  
	local contest = 0 
	local character = player.Character
	local opponents = datafolder[ player.Name ].Server.Opponents
	local root = character.HumanoidRootPart 
	local h1 = character.Humanoid.BodyHeightScale
	local goal = functions:findclosestPart(root.Position, "goal")
	local cf = CFrame.new(root.Position, Vector3.new(goal.Position.X, root.Position.Y, goal.Position.Z))
	--for i,v in pairs(opponents:GetChildren()) do 
	--local plr = players[v.Name]
	--local char = plr.Character
	for i,v in pairs(workspace:GetChildren()) do 
		if v:FindFirstChild("Humanoid") then
			local char = v
			local h2 = char.Humanoid.BodyHeightScale
			local hrp = char.HumanoidRootPart 
			local stat = 99-- datafolder[plr.Name].Attributes.ShotContest 
			local mag = (root.Position - hrp.Position).Magnitude
			local dir = functions:getMoveDirection(hrp.Position, char.Humanoid.MoveDirection, root.Position) 
			print(root.Position) 
			print(hrp.Position) 
			print(cf.LookVector)
			local dot = ((root.Position - hrp.Position).Unit):Dot(cf.LookVector) 
			if mag < 5 then
			print(math.round(dot))
			

			end

		end

Dot product is literally just multiplication and addition, so chances are one of your inputs is null or something

Are all three of these prints printing properly? Not null or anything weird?

print(root.Position) 
print(hrp.Position) 
print(cf.LookVector)

yes they print properly and I get no errors.

print(math.round(dot))

Is this the print statement thats printing null?
If so have you tried printing just dot without the rounding

I’ve tried both and they return the same thing.

I mean pretty much the only way to make a dot product -nan(ind) is to make a super high number or give it -nan(ind) as an input
Both of your vectors are unit vectors so that shouldnt be the problem

Can you show the full output and all of the prints in the script perhaps?
If that doesnt show anything I dont even know what else I would do to be honest

What does -nan(ind) even mean I think knowing that could help me solve the problem.

Its an indeterminate number, like 1/0, math.huge*0, many math functions will return -nan(ind) when given infinity as an input too like math.cos(math.huge), etc

This is most likely your problem, if root.Position and hrp.Position are identical the unitvector will not be a defined number as you can’t get a valid unitvector from a null vector.

1 Like