Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make a hide feature and have the NPC go away?

Asked by 4 years ago
Edited 4 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:


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)
0
Hey bud, can you indent your lines of code so that it's easier to read? Thanks! :) Sensei_Developer 298 — 4y
0
? Au_Naturel -26 — 4y

1 answer

Log in to vote
0
Answered by
raid6n 2196 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

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

Answer this question