Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Can I make a door only CanCollide for NPC?

Asked by 7 years ago
Edited 7 years ago

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)
0
Uh, this is half-assed but, you might be able to use FE to your advantage here. AZDev 590 — 7y
0
I'm a pretty new scripter so I mean this is all I would know how to do for now... What does FE stand for? YouSNICKER 131 — 7y
0
FE = Filtering Enabled spiderman90438 17 — 7y
1
Add the door from a client's localscript.Thus,the door is visible for the player,but not to the NPC. Reshiram110 147 — 7y
View all comments (2 more)
0
I like that idea, and it would probably work the best. ^ User#11440 120 — 7y
0
Thanks for the tips guys I'll try it out! I never thought about making the doors for the client.. YouSNICKER 131 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

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.

Ad

Answer this question