How to prevent NPCs from killing each other and/or chasing the other NPC?

  1. What do you want to achieve? I want to prevent an NPC from killing and chasing teh other NPC.

  2. What is the issue? I don’t know how to do that, though I just want the NPC to stop chasing the other one. I don’t need the “Cancelling Damage” script.

  3. What solutions have you tried so far? I looked for some posts but they’re just not it.

I also wanna know this so I can learn more about scripting and/or if I or my friends wanna make some other games.

2 Likes

If you already have a script that is controlling the NPCs now it would help if you could share it so we can understand what the script is doing that you wish to change.

3 Likes

Could you share your AI script?

2 Likes

Run an if statement to see whether or not the target is a player or not.

It should work then

3 Likes

here is an idea, check if it chases a player (edit

local player = game.Players:GetPlayerFromCharacter(put character that the npc is chasing here)
if player then
--do your code here
end
2 Likes

For your target search function, instead of looping through all Humanoids in workspace, you should loop through game:GetService("Players"):GetPlayers() which returns an array of all the players.

3 Likes
if not game.Players:GetPlayerFromCharacter(NPC) then