So what I want to do is make a smart killing npc that can go through doors and follow the player without jumping into a wall for the whole game.
I have everything down except how to make the npc focus on a player not a block or another NPC
First we need to find the nearest person.
Example:
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 end end
Boom, we did it. Now we want the player to go the Player.
Script Example:
NPC.Humanoid:MoveTo(player.Character.Humanoid)
Final script:
game.Players.PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(character) 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)