Making it so the player can't activate something when looking too far up

Hello,
I have recently gotten back into scripting and have ran into an issue. I’m making a system similar to Metro Exodus’s backpack system, where the player presses a keybind, lowers to the ground with their camera, and can look in their backpack. However, I have ran into a roadblock. I am trying to make it so if the player is looking too far down or too far up, they can’t activate the backpack system. I have tried numerous options from lookvectors, to WorldToScreenPoint, and I just cannot get it to work. I understand you can’t compare Vector3’s to numbers, but I looked at various other topics like this, and cannot find a fix. If anyone can help me out, that’d be appreciated.

Main code snippet:

if cam.CFrame.YVector <= 6 then
		local Character = plr.Character or plr.CharacterAdded:Wait()
		local HUMAN = Character:FindFirstChild('Humanoid')
		on = false
		HUMAN.WalkSpeed = 16
		HUMAN.JumpPower = 50
		ChangeCameraOffset(Vector3.new(0, 0, 0))
		plr.PlayerGui:FindFirstChild('Inventory').Enabled = false
		print(HUMAN.CameraOffset)

If anyone needs to look at the ChangeCameraOffset function:

function ChangeCameraOffset(Offset) -- [Vector3]Offset
	if not plr.Character then plr.Character = plr.Character or plr.CharacterAdded:Wait() end
	local Humanoid = plr.Character:WaitForChild("Humanoid")

	local Tween = TweenService:Create(Humanoid, TweenInfo.new(0.5), {CameraOffset = Offset})
	Tween:Play()
end

If you need to see any more of the script, please let me know. Thanks!

you can use lookvector

if (workspace.Camera.CFrame.LookVector.Y <= -0.7) then 
print("looking down")
elseif (workspace.Camera.CFrame.LookVector.Y >= 0.6) then
print("looking up") 
end
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.