I have the code here basically the NPC walks out the house and back in after doorbell is rang. I want it to where only the NPC can go through the door while the Player cannot.
local NPC = script.Parent.Parent.H1.NPC.Humanoid local NPCMod = script.Parent.Parent.H1['NPC'].Torso local pos1 = script.Parent.Parent.H1.inPart.Position local pos2 = script.Parent.Parent.H1.outPart.Position local door = script.Parent.Parent.H1.Door deb = true script.Parent.Clicker.ClickDetector.MouseClick:connect(function(wat) if deb == true then deb = false -- NPC moves outside when doorbell clicked door.CanCollide = false -- I do not like this because the Player can go through the door too! NPC:MoveTo(pos2) wait(.25) NPCMod.Anchored = true door.CanCollide = true wait(5) NPCMod.Anchored = false -- NPC moves inside after 5 seconds door.CanCollide = false NPC:MoveTo(pos1) wait(.27) NPCMod.Anchored = true door.CanCollide = true deb = true end end)
You could honestly just probably check anything that only exists in the NPC and check to see if whatever touches the door has it present. So, like, if the NPC's model name is "Jeff," then check to see if whatever touched the door is named "Jeff," and if not, don't open it (unless, of course, if someone on ROBLOX is simply named "Jeff" O_O). Example:
name = "Jeff"; debounce = false; script.Parent.Touched:connect(function(hit) if not debounce then debounce = true; local thingThatTouchedTheDoor = hit.Parent; if thingThatTouchedTheDoor.Name == name then script.Parent.CanCollide = false; wait(0.5) -- maybe a bit longer, depending on how fast the npc is able to make it through the door >_> script.Parent.CanCollide = true; end debounce = false; end end)
There's definitely a more efficient way to accomplish what you seek, but this is just off the top of my head.