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 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:

01game.Players.PlayerAdded:connect(function(player)
02    player.CharacterAdded:connect(function(cha****racter)
03if character then
04local function movetonpc()
05local vecPoint = workspace.NPC.Humanoid.Position
06local closestPlayer, smallestMagnitude = nil,math.huge
07 
08for _, player in pairs(game.Players:GetPlayers()) do
09     local distance = player:DistanceFromCharacter(vecPoint)
10     if distance < smallestMagnitude then
11          smallestMagnitude = distance
12          closestPlayer = player
13 
14NPC.Humanoid:MoveTo(player.Character.Humanoid)
15     end
View all 23 lines...
0
Hey bud, can you indent your lines of code so that it's easier to read? Thanks! :) Sensei_Developer 298 — 5y
0
? Au_Naturel -26 — 5y

1 answer

Log in to vote
0
Answered by
raid6n 2196 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago
01game.Players.PlayerAdded:connect(function(player)
02    player.CharacterAdded:connect(function(character)
03if character then
04player = notsafe
05local Safepart = workspace.SafePart
06local function onTouched(part)
07player = safe
08end
09Safepart.Touched:Connect(onTouched)
10local function onTouched(part)
11player = safe
12end
13local function offTouched(part)
14player = notsafe
15end
View all 40 lines...
Ad

Answer this question