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

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

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
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.

Ad

Answer this question