Very Confused At This Conditional Statement

function getPosition(plr)
	local success, result = pcall(function()
		return plr.Character.HumanoidRootPart.Position
	end)

	if success == false or not(typeof(result) == Vector3) then
		wait(.25)
		print(result)
		print("Retrying to get position of player root part. pcall returned " .. tostring(success) .. ". Response returned " .. typeof(result) .. ".")
		getPosition(plr)
	else
		print("Successfully got player position.")
		return result
	end
end

local deathAlt = game:GetService("ServerScriptService").DeathAltitude.Value

game:GetService("Players").PlayerAdded:Connect(function(plr)

	spawn(function()
		repeat wait() until (plr.Character)
		wait(2)

		while wait(.5) do
			local pos = getPosition(plr)
			print(pos)
			
			if pos.Y <= deathAlt then
				print("Player " .. plr.Name .. " is below the safe altitude.")
				plr.Character.Health = 0
			else
				print("Player ".. plr.Name .. " is at a safe altitude.")
			end
		end
	end)
end)

Basically, the code above prints out the following:

Retrying to get position of player root part. pcall returned true. Response returned Vector3.

Alright, so my result, which is the response of the pcall, is a Vector3 value. This means that not(typeof(result) == Vector3) returns false. If the success is true, which returns false on the first condition, then the second condition ALSO returns false, why is it still running the first code block which attempts to retry when both statements of the ‘or’ condition are false??

No this should always be true. typeof always returns a string, not a table. not (a == b) is pointless, you’re just reinventing ~=.

So change that to

typeof(result) ~= "Vector3"

Ah I didn’t know typeof() returned a string, my bad. Also totally forgot about the ~= operator. :joy: Thanks for the response :+1: I will try running it again.

Update: It worked, thanks again for the help :slight_smile: