NPC-Touch Only Door

Hello!
(Heads up, I’m bad at coding.)

I am trying to code a door where if an NPC were to touch it, it would automatically open. However, if the player wants to get inside they have to click it, so the If Touched statement won’t trigger if the player would to touch it:

local door = script.Parent
local Player = game.Players:GetPlayers("Player")

door.Touched:Connect(function(char)
	if  char.Parent == not Player.Character then
		-- Door Open Script
    end
end

door.ClickDetector.MouseClick:Connect(function() -- If Player Then
      -- Door Open Script
end)

The issue is that when I set it to “not Player.Character”, the player nor NPC’s can open the door. But if I set it to the player only, both the player and NPC’s can open it (I hope this all makes sense). How can I fix this?

1 Like

!= is not equals, use that instead. I usually only use “not” when I’m checking if something doesn’t exist

1 Like

Player is set to game.Players:GetPlayers()
:GetPlayers returns a table/list of players and not a single player.

To check if its a player or not, just do this

if game.Players:GetPlayerFromCharacter(char.Parent) then
   -- Is a player
else
   -- NPC
end
1 Like

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