Trying to create a part that can be walked through when not seen, but first person doesn't follow the script

I’m trying to create a puzzle where the player has to look away from the part in order to walk through it, I currently have a script that works fine but doesn’t work when the player goes into first person, the player is still able to walk through the part while looking at it in first person.

I can’t disable first person because the player has to go into first person to turn around.

local camera = workspace.CurrentCamera

game:GetService("RunService").RenderStepped:Connect(function()
	local screenPos, onScreen = camera:WorldToScreenPoint(part.Position)

	if not onScreen then
		part.CanCollide = false
	else
		part.CanCollide = true
	end
end)

(script was made by a friend i take no credit <3)

You can use Vector3:Dot(),

local Camera = workspace.Camera
local Part = workspace.Part


task.spawn(function()
	while true and task.wait(0.1) do 
		local Dot = Camera.CFrame.LookVector:Dot(Part.CFrame.LookVector)

		if (Dot >= 0.1) then 
			Part.CanCollide = false 
		else 
			Part.CanCollide = true
		end
	end
end)

1 Like

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