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

Script function by NPC OnTouch?

Asked by 6 years ago
Edited 6 years ago

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):

1door1.CFrame = door1.CFrame * CFrame.new(-0.125, 0, 0)
2door2.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).

0
You should be able to use the part.Touched event because it fires when any part touches that part. Then it's as simple as checking if the part's parent is either an NPC or player by looking for a humanoid. xPolarium 1388 — 6y

1 answer

Log in to vote
0
Answered by
tomekcz 174
6 years ago
01Delay = false -- set delay
02 
03script.Parent.Touched:Connect(function(part)
04    if not Delay then -- if delay == false then is this same
05        if part.Parent:FindFirstChild("Humanoid") then
06            Delay = true
07            --Put your script here
08            wait(1) -- change value if you want
09            Delay = false
10        end
11    end
12 
13end)

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.

Ad

Answer this question