How do I make a hide feature and have the NPC go away?
Asked by
5 years ago Edited 5 years ago
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:
01 | game.Players.PlayerAdded:connect( function (player) |
02 | player.CharacterAdded:connect( function (cha****racter) |
04 | local function movetonpc() |
05 | local vecPoint = workspace.NPC.Humanoid.Position |
06 | local closestPlayer, smallestMagnitude = nil , math.huge |
08 | for _, player in pairs (game.Players:GetPlayers()) do |
09 | local distance = player:DistanceFromCharacter(vecPoint) |
10 | if distance < smallestMagnitude then |
11 | smallestMagnitude = distance |
12 | closestPlayer = player |
14 | NPC.Humanoid:MoveTo(player.Character.Humanoid) |