Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Script function by NPC OnTouch?

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

1 comment

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.

1 answer

✓ Accepted answer
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.

This discussion is preserved as it was. New answers, comments, and votes are closed.