I am currently making a door script that will open when a specific NPC touches it by using OnTouch function (or by magnitude, if not possible). The door will move two bricks once the door it's supposed to be opened (the default way of opening it is by clicking on a button):
door1.CFrame = door1.CFrame * CFrame.new(-0.125, 0, 0) door2.CFrame = door2.CFrame * CFrame.new(-0.125, 0, 0)
Is there a way to make this happen when the NPC actually touches the door by having this function in the door's actual script (I already tried OnTouch, but it won't work).
Delay = false -- set delay script.Parent.Touched:Connect(function(part) if not Delay then -- if delay == false then is this same if part.Parent:FindFirstChild("Humanoid") then Delay = true --Put your script here wait(1) -- change value if you want Delay = false end end end)
Now i will explain this code RENEMBER TO PUT THAT SCRIPT INSIDE PART
You dont need to place delay if you want Why delay is used - if you will dont place delay then this will happen - Players leg touched part, Players leg touched part, Players leg touched part with delay it will be like Players leg touched part. :FindFirstChild("Humanoid") - every player model owns humanoid.