How do I make a script that does this:

Hello! I need help making a script where if an npc with the name NPC touches a part, it will do this:

local ServerStorage = game:GetService("ServerStorage") 3 local SimplePath = require(ServerStorage.SimplePath) 4 ​ 5 --Define npc 6 local Dummy = workspace.Dummy 7 ​ 8 -- Define a part called "Goal" 9 local Goal = workspace.Goal 10 ​ 11 --Create a new Path using the Dummy 12 local Path = SimplePath.new(Dummy) 13 ​ 14 --Helps to visualize the path 15 Path.Visualize = true 16 ​ 17 --Dummy knows to compute path again if something blocks the path 18 Path.Blocked:Connect(function() 19 Path:Run(Goal) 20 end) 21 ​ 22 --If the position of Goal changes at the next waypoint, compute path again 23 Path.WaypointReached:Connect(function() 24 Path:Run(Goal) 25 end) 26 ​ 27 --Dummmy knows to compute path again if an error occurs 28 Path.Error:Connect(function(errorType) 29 Path:Run(Goal) 30 end) 31 ​ 32 Path:Run(Goal)

2 Likes

Would this work:

local NPC = NPC.workspace local safepoint = sp.workspace if NPC touching sp then (My code here) end

1 Like
local NPC = workspace:WaitForChild("NPC") --npc model
local part = workspace:WaitForChild("Part")
local debounce = false

for i, v in pairs(NPC:GetChildren()) do
	if v:IsA("Part") or v:IsA("MeshPart") then
		v.Touched:Connect(function(hit)
			if hit == part then
				if debounce then
					return
				end
				debounce = true
				--do stuff
				task.wait(10)
				debounce = false
			end
		end)
	end
end
1 Like