Detect if a player is in npc

I know some basic idea of true and false, but how would I detect if a player is in the NPC or not? I want it so that if the player press e and he is in the NPC, he goes back in

heres my script:

local Character = script.Parent
local Npc = game.Workspace.Npc
local camera = workspace.CurrentCamera


UIS.InputBegan:Connect(function(Key, Chatted)
	if Chatted then
		return
	end

	if Key.KeyCode == Enum.KeyCode.E then
		local Player = game.Players.LocalPlayer
		camera.CameraSubject = Npc.Humanoid
		Player.Character = Npc		

	end
end)
1 Like

Very confused on what you’re trying to achieve, maybe try elaborating it a little?

Are you trying to have the Camera focus on the Npc’s Humanoid?

Referencing from the OP, I think he’s wanting to check if the CameraSubject is focused on the NPC’s POV? Either that or a check for the NPC’s Parent

You could just check if the CameraSubject is equal to the Humanoid using a conditional statement possibly? You’d need to detect some change though for when the CameraSubject changes it’s view:

local Character = script.Parent
local Npc = game.Workspace.Npc
local camera = workspace.CurrentCamera


UIS.InputBegan:Connect(function(Key, Chatted)
	if Chatted then
		return
	end

	if Key.KeyCode == Enum.KeyCode.E then
		local Player = game.Players.LocalPlayer
		camera.CameraSubject = Npc.Humanoid
		Player.Character = Npc		
	end
    
    camera:GetPropertyChangedSignal("CameraSubject"):Connect(function()
        if camera.CameraSubject ~= Npc.Humanoid then
            --Implement your code here
        end
    end)
end)

does this work?

        if camera.CameraSubject ~= Npc.Humanoid then
           camera.CameraSubject = plaayer --????? like this???????
        end
    end)
end)