Is it possible to make a place where a player can hide from my pathfinding NPC and the NPC will go away when the player is in that spot?
Heres the NPC pathfinding script:
game.Players.PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(cha****racter) if character then local function movetonpc() local vecPoint = workspace.NPC.Humanoid.Position local closestPlayer, smallestMagnitude = nil,math.huge for _, player in pairs(game.Players:GetPlayers()) do local distance = player:DistanceFromCharacter(vecPoint) if distance < smallestMagnitude then smallestMagnitude = distance closestPlayer = player NPC.Humanoid:MoveTo(player.Character.Humanoid) end end end while wait(.01) do movetonpc() end end end) end)
game.Players.PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(character) if character then player = notsafe local Safepart = workspace.SafePart local function onTouched(part) player = safe end Safepart.Touched:Connect(onTouched) local function onTouched(part) player = safe end local function offTouched(part) player = notsafe end Safepart.TouchEnded:Connect(offTouched) local function movetonpc() local vecPoint = workspace.NPC.Humanoid.Position local closestPlayer, smallestMagnitude = nil,math.huge for _, player in pairs(game.Players:GetPlayers()) do local distance = player:DistanceFromCharacter(vecPoint) if distance < smallestMagnitude then smallestMagnitude = distance closestPlayer = player if player == notsafe then NPC.Humanoid:MoveTo(player.Character.Humanoid) else print(“Player is safe”) end end end end while wait(.01) do movetonpc() end end end) end)