The title says it. Also I have no idea how to do it. I already tried renaming the HumanoidRootPart or the Humanoid, but the NPC still chases me. How to do it? I don’t need any animations or stuff, I just need to know how to do it. idk where to start because I’m just average at scripting
Do you have existing code you can share so we can assist?
Well, I do have one but the place that has it got deleted, idk what happened to it actually, also I tried using Collisions but it doesn’t work. I tried using collisions because an NPC needs to find a way to get the player.
So how are you going to have your NPCs detect players?
You could setup your NPCs to, every so often, perform a raycast towards a direction (or multiple) and then detect if they see anything there, and if they do then you would add your code to specify if the player is “hiding” or not, and if they’re detectable or not
What you could potentially do is one of two things:
1- you could add a value to the player or the character, and then change the value when the player is in certain places. If let’s say, the value is true, then the NPC would stop chasing the player, and vice versa.
2- or like SnazpantsMixer (avoiding unnecessary pinging) said, you could use raycasting to see if the NPC can the player or not.
The first thing you said, would I return a function to end if a player is hidden?
Well, depends on what script you’re using. Typically, you’d be checking where the player is every second, and what you could do is add a line where it checks whether the value is true or not. If you do something like:
If player.ValueName == false then
-- your function here
else
-- do nothing (basically stop chasing the player)
end
What I would do, based on your description, is get the list of players in your game, pick one at random, then use raycasting to see if the player is visible to the NPC (direct line of sight). If not, pick another player at random and do the same thing. Keep doing this until the NPC can see a player. Then you can use the pathfinding service to calculate a path to the player.
After that, depending on what you want to do, you can do raycast every so often (like once a second) to see if the player is still visible. If not, then pick a different player.
whats that system called?? i wanna search up a tutorial ive been struggling with raycast!!!