The script below is a child of an npc. Basically I wanted to make it so that when the npc is touched by a player that it will stop moving to random parts. But when I found out that my script didn't work I just wanted to check if the npc would detected being touched in general and that didn't even go through.
local pathdeterminer
local npc = script.Parent
local humanoid = npc:WaitForChild("Humanoid")
local inbattle = false
while inbattle == false do
pathdeterminer = "p" .. math.random(1,6)
if(pathdeterminer == "p1") then
humanoid:MoveTo(game.Workspace.Points.p1.Position)
humanoid.MoveToFinished:Wait()
end
if(pathdeterminer == "p2") then
humanoid:MoveTo(game.Workspace.Points.p2.Position)
humanoid.MoveToFinished:Wait()
end
if(pathdeterminer == "p3") then
humanoid:MoveTo(game.Workspace.Points.p3.Position)
humanoid.MoveToFinished:Wait()
end
if(pathdeterminer == "p4") then
humanoid:MoveTo(game.Workspace.Points.p4.Position)
humanoid.MoveToFinished:Wait()
end
if(pathdeterminer == "p5") then
humanoid:MoveTo(game.Workspace.Points.p3.Position)
humanoid.MoveToFinished:Wait()
end
if(pathdeterminer == "p6") then
humanoid:MoveTo(game.Workspace.Points.p4.Position)
humanoid.MoveToFinished:Wait()
end
wait(0.5)
end
humanoid.Touched:Connect(function(hit)
local check = hit.Parent:WaitForChild("Humanoid")
if check ~= nil then
print("TOUCHED")
inbattle = true
end
end)

1 comment
thank you!