I have spent many painstakingly long hours trying to learn Pathfinding and other things like this, but this was really easy to follow and somewhat easy to understand. Liked and subscribed!
Thank you, I created a enemy in roblox studio back in 2016 I believe that I wanted to make for a game, but got discouraged when I couldn't figure out how to get it to chase players. Now you've given me a basic idea on what I need to do in order to create enemies for my games.👍
This video is 1 year old but yet it helped me out so much 🥰. 3 days of looking for the perfect video was worth it, you earned a like and subscription from me.
Awesome video!! After searching multiple different videos yours was the one that explained it all and made it easy. I liked the speed of the video, the explanation of the lines of code, and the tenor of your audio (no screaming or crazyness). Great job! I really appreciate it!
Sorry I am late, but this tutorial helped me a lot, but I didn't understand all of it, so I got the model that you put in, sorry. Great tutorial! Your voice was loud and clear, you said everything so understandable.
This is so cool and I had fun following along!! I still struggle to understand the "why" for a lot of things in script as a newbie, but I'm sure it'll make sense the more I learn. thank you for this video. :^D
Yo, i can tell this man is gonna be pretty big soon. I mean content is pretty good and he's pretty master. I just have 1 tip to get bigger. Make more tutorials that people are most likely going to search for. Like this video is a pretty good one. Keep it up!
Workspace.Model.Humanoid.EnemyController:20: attempt to index nil with 'Position' So I created my own model and rigged it my self and tried to implement the code on it but it just pops up as Workspace.Model.Humanoid.EnemyController:20: attempt to index nil with 'Position' idk if its because its a four legged model instead of a r15 or r6 model but it still has the humanoid in it. I could really appreciate the help.
sat here for 20 minutes (real) looking through the script for why it wouldnt work whatsoever, and i finally realized i forgot an end at line 31. coding is so fun i want to do it everyday
I have an error saying "Unable to cast double to Vector3". My script is : local RunService = game:GetService("RunService") local Players = game:GetService("Players") local Humanoid = script.Parent local root = Humanoid.Parent.PrimaryPart local targetDistance = 20 local stopDistance = 5 function FindNearestPlayer() local playerList = Players:GetPlayers() local nearestPlayer = nil local distance = nil local direction = nil for _, player in pairs(playerList) do local character = player.Character if character then local distanceVector = (player.Character.HumanoidRootPart.Position - root.Position) if not nearestPlayer then nearestPlayer = player distance = distanceVector.Magnitude direction = distanceVector.Unit elseif distanceVector.Magnitude < distance then nearestPlayer = player distance = distanceVector.Magnitude direction = distanceVector.Unit end end end return nearestPlayer, distance, direction end RunService.Heartbeat:Connect(function() local nearestPlayer, distance, direction = FindNearestPlayer() if nearestPlayer then if distance = stopDistance then Humanoid:Move(distance) else Humanoid:Move(Vector3.new()) end end end) Please someone help.
Btw can you paste script here im having hard time making a game so putting the script in the comments will really help me. Even if you dont thx for tutorial
Move should be only used on the humanoid, which I set as a variable. If the error says "not a valid member of part", then either the humanoid variable must be incorrectly set to a part (such as the humanoid root) rather than the humanoid, or you are trying use :move() on the wrong variable. Hope this helps!
Make sure to use character.HumanoidRootPart.CFrame.Position instead of character.HumanoidRootPart.Position to calculate the distanceVector if you're getting errors about that
For anyone what for R6 Rig Type (because this script not work on r6 type only r15) Note: It all rewrite by ChatGPT local RunService = game:GetService("RunService") local Players = game:GetService("Players") local humanoid = script.Parent local root = humanoid.Parent.Head local targetDistance = 20 local stopDistance = 5 function findNearestPlayer() local playerList = Players:GetPlayers() local nearestPlayer = nil local distance = nil local direction = nil for _, player in pairs(playerList) do local character = player.Character if character then local distanceVector = (player.Character.Head.Position - root.Position) if not nearestPlayer then nearestPlayer = player distance = distanceVector.Magnitude direction = distanceVector.Unit elseif distanceVector.Magnitude < distance then nearestPlayer = player distance = distanceVector.Magnitude direction = distanceVector.Unit end end end return nearestPlayer, distance, direction end RunService.Heartbeat:Connect(function() local nearestPlayer, distance, direction = findNearestPlayer() if nearestPlayer then if distance = stopDistance then humanoid:Move(direction) else humanoid:Move(Vector3.new()) end end end)
(pls reply) (in the script) when pressing enter there are a couple of spaces and the text appears more to the right, right. Does it mater if the space is there? (same thing about the "end" does it mater if it is there?
Trying to follow this using an enemy model I brought in from Blender. I got it to work for the R15 model but when I try and change the wording based on the model I am using I am getting a ton of errors so thinking I'm changing it wrong. Any tips on doing this for an injected model? This is the current error I am getting and it seems to not like Vector3.new: Move is not a valid member of MeshPart "Workspace.Enemies.Candy_Land.Hot_Choc_Mob_1.Plate". Thank you in advance
When testing with multiple players the script seems confused about which player/where to target. It seems to be trying to target both players at the same time instead of focusing on the single closest player
Thank you, this video was very helpful for me, but i'm curious about how can i make npcs go back to their spawn or other places after they stopped chasing player?
i wrote this exactly local distanceVector = (player.Character.HumanoidRootPart.Position - root.Position) but why does it gives an error. Workspace.Dummy.Humanoid.Script:20: attempt to index nil with 'Position' ..healp pls how?
For some reason when I added the script to my characters it doesn’t work, but the freemodel itself works, how do I fix this?? Edit: for some reason it does work but when my npc is made higher like by less than a stud it won’t work. It needs to be on the same ground level. Do you know a possible fox for this?
why does the end ()) has a wrong in it ? Runservice.Heartbeat:Connect(function() local nearestplayer, distance, direction = FindNearestPlayer() if nearestplayer then if distance = stopDistance then humainoid:Move(direction) else humainoid:Move(Vector3.new()) end end)
Hey! was rlly helpful, but for some reason my model came with humanoid but not humanoid root part? my model isnt r15 if that makes any difference. how do i get one?? it isnt in local
Can anyone help me? I tried this on my own model (a skeleton) which has a humanoid and is rigged properly and such. When I run this script, the skeleton just disappears for some reason. I tried pasting the script into a regular R15 rig and it works fine. Why doesn't it work on my skeleton? Great tutorial though
can you create a monster that randomly attacks the player like Charles from "Choo Choo Charles" I understand that this game was made on a different game creation engine, but if possible, please do a tutorial on this
I have spent many painstakingly long hours trying to learn Pathfinding and other things like this, but this was really easy to follow and somewhat easy to understand. Liked and subscribed!
Same.
Same
@@Charley1289
Same x2
A moment of silence for this man, he didn't have coffee this morning 😢
btw awesome tutorial my man
MrModuleScript:"Now we have to deal with a nil value in our heartbeat" bro thats dark
lol
lol
Oh.....
lol
If it isn't moving make sure the torso or humanoidrootpart is unanchored
YES THIS WORKED!! THANK YOU!!
Thank you, I created a enemy in roblox studio back in 2016 I believe that I wanted to make for a game, but got discouraged when I couldn't figure out how to get it to chase players. Now you've given me a basic idea on what I need to do in order to create enemies for my games.👍
Have u finished it yet ? what is ur user name
@@Zero9xi No. Also thanks to my own situatiion I don't think I will be able to finish it for quite some time.
@@coolcosmic4351 mk
This video is 1 year old but yet it helped me out so much 🥰. 3 days of looking for the perfect video was worth it, you earned a like and subscription from me.
can you text me the script it doesnt work for me
I thought it would not work, like some of the other tutorials I tried, but this guys a legend!!!
Im just starting to script and your tutorial helped me more than I could ever imagine
:D Glad to hear that!
Awesome video!! After searching multiple different videos yours was the one that explained it all and made it easy. I liked the speed of the video, the explanation of the lines of code, and the tenor of your audio (no screaming or crazyness). Great job! I really appreciate it!
Thank you SO SO much. I'm making a survival game and I've been searching for a great tutorial like this! Glad I found this.
I would love to play this
yo how do you add more health
@@TyOstranderMMA health is inside the humanoid
Great Tutorial! So clear and works great. Keep it up
Sorry I am late, but this tutorial helped me a lot, but I didn't understand all of it, so I got the model that you put in, sorry. Great tutorial! Your voice was loud and clear, you said everything so understandable.
Finally! I got it to work, I just had to un anchor the humanoid root part! Thanks so much for the great vid it helped me so much
Finally, a video that doesn't make me copy and paste the script
Looks like the video was recorded in 720p... I'm so sorry. Woops! The next videos will be back to 1080p. Sorry if the video looks a little blurry!
thank u for ur helpful tutorial , u just saved me hours of learning
DUDE THANK YOU SO MUCH! I have been looking for hours for a script like this!
@@URANUS113 Yes
Thank you so much! It took me forever to find a tutorial that i understand. You earned a like and a sub :)
Glad you found it helpful!
was desperated until I found my mistake is a syntax error in the script; now it works fine for me Thanks a lot, keep going
Glad you got it working! Part 3 is on its way!
Thank you for this video, it helped out so much, and thanks for going slow with writing the code and explaining the important parts!
I'm so happy this works with r6 as well
This is so cool and I had fun following along!! I still struggle to understand the "why" for a lot of things in script as a newbie, but I'm sure it'll make sense the more I learn. thank you for this video. :^D
how's it going for you?
ty bro, me and my friend needed the best tutorial on this :)
Yoo thanks for the tutorial! it helped me a lot :D
incredibly useful tutorial, cant count the number of hours ive been trying to learn how to do this. Liekd and subscribed.
I guess I am just really dumb and did something wrong because I downloaded the script and it worked but mine did not lol. You have earned a sub man!
Yo, i can tell this man is gonna be pretty big soon. I mean content is pretty good and he's pretty master. I just have 1 tip to get bigger. Make more tutorials that people are most likely going to search for. Like this video is a pretty good one. Keep it up!
We just gotta hope he uploads more tutorials, the first 2 were helpful
This is really helpful for making a Partygoer in my Backrooms game!
thank you are the only one that i found that does not do copy and paste
Epic video Didn't know a tutorial like this existed
This will really help with my friends game! Thanks alot!
thanks i watched this for a game with my friends :)
bro earned a sub faster than me looking for my dad
I can't figure out why my custom rig isn't working with the Script
Workspace.Model.Humanoid.EnemyController:20: attempt to index nil with 'Position' So I created my own model and rigged it my self and tried to implement the code on it but it just pops up as Workspace.Model.Humanoid.EnemyController:20: attempt to index nil with 'Position'
idk if its because its a four legged model instead of a r15 or r6 model but it still has the humanoid in it. I could really appreciate the help.
I'm having the same issue,
Workspace.Model.Humanoid.Script:24: attempt to index nil with 'Position'
just set the primary part of your model (usually HumanoidRootPart).
@@Spearit_S Yep that was the problem, thank you.
Just add the following line if r15 does not move
root.Anchored = false
Thank you so much! I knew i had an anchoring issue, i just did not know how to fix it.
sat here for 20 minutes (real) looking through the script for why it wouldnt work whatsoever, and i finally realized i forgot an end at line 31. coding is so fun i want to do it everyday
use script analysis and output
very epic and cool
If I could subscribe twice, I would. No thumbs up, all my fingers up! (Which doesnt make sense but still...) I'm oof to part 2!!
Thank you so much for a legit script that works very nicely!
this is the birth of the student enemy for me
I have an error saying "Unable to cast double to Vector3". My script is :
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local Humanoid = script.Parent
local root = Humanoid.Parent.PrimaryPart
local targetDistance = 20
local stopDistance = 5
function FindNearestPlayer()
local playerList = Players:GetPlayers()
local nearestPlayer = nil
local distance = nil
local direction = nil
for _, player in pairs(playerList) do
local character = player.Character
if character then
local distanceVector = (player.Character.HumanoidRootPart.Position - root.Position)
if not nearestPlayer then
nearestPlayer = player
distance = distanceVector.Magnitude
direction = distanceVector.Unit
elseif distanceVector.Magnitude < distance then
nearestPlayer = player
distance = distanceVector.Magnitude
direction = distanceVector.Unit
end
end
end
return nearestPlayer, distance, direction
end
RunService.Heartbeat:Connect(function()
local nearestPlayer, distance, direction = FindNearestPlayer()
if nearestPlayer then
if distance = stopDistance then
Humanoid:Move(distance)
else
Humanoid:Move(Vector3.new())
end
end
end)
Please someone help.
yoo broo, really apprechiate that you made this vid, also do you know how i could make the dummy walk faster?
after I downloaded the dummy it kept spawning in every of my baseplates. How can you make it stop?
8:37 bro direction is an absolute UNIT
hehehehehehehehehehehehehehehhehehehehehhehhhehhe E
E
e
e
ᵉ
ᵉ
.
.
spiderman
on his way home
It doesn't work for me. I've tried lots of NPC tutorials, but nothing has happened. My dummy doesn't move a stud. Is my studio bugged??
Make sure it isn't anchored. That seems to be the most common cause of this problem.
You are a w man this will help me so much thank you🙂
this helped me out so much
HOW IS THIS 2 WEEKS AGO?!
it did'nt work for me :( can you tell me what i mabye did wrong?
everytime i try the npc in studio and click play, there are hundreds of dummys on top of me, please help!
It gives me an error: "Workspace.StarterCharacter.EnemyController:20: attempt to index nil with 'Position' - Server"
Can anyone help me?
I Subscribed!
Thanks For The Video!
when i use a kickback move it completely flys away
I have a problem, my characters that I added aren't taking damage from anything, does anyone have a fix
Btw can you paste script here im having hard time making a game so putting the script in the comments will really help me.
Even if you dont thx for tutorial
do i have to put it to nil or some other name?
Does anyone know how to fix the error where it says that move is not a valid member of part?
Move should be only used on the humanoid, which I set as a variable. If the error says "not a valid member of part", then either the humanoid variable must be incorrectly set to a part (such as the humanoid root) rather than the humanoid, or you are trying use :move() on the wrong variable. Hope this helps!
@@mrmodulescript ok thanks I’ll try it.
@@mrmodulescript OMG IT WORKED BRO TYSM!
@@mrmodulescript IM MAKING A HORROR GAME SO THIS WILL HELP A LOT
Part 1 results : How to make a "peacefull" enemy npc
Well you add a kill script, modify the damage and done
That what I did with a npc
@@C4nd4nThats the part 2
can you make a tutorial so that we can make a mesh with a humanoid in it attack you instead of a dummy
there a way to make it only target you when you're on a certain team?
can I use r6 dummy?
How do u make the NPC Track you down trough obstacles
Make sure to use character.HumanoidRootPart.CFrame.Position instead of character.HumanoidRootPart.Position to calculate the distanceVector if you're getting errors about that
thank you
For anyone what for R6 Rig Type (because this script not work on r6 type only r15)
Note: It all rewrite by ChatGPT
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local humanoid = script.Parent
local root = humanoid.Parent.Head
local targetDistance = 20
local stopDistance = 5
function findNearestPlayer()
local playerList = Players:GetPlayers()
local nearestPlayer = nil
local distance = nil
local direction = nil
for _, player in pairs(playerList) do
local character = player.Character
if character then
local distanceVector = (player.Character.Head.Position - root.Position)
if not nearestPlayer then
nearestPlayer = player
distance = distanceVector.Magnitude
direction = distanceVector.Unit
elseif distanceVector.Magnitude < distance then
nearestPlayer = player
distance = distanceVector.Magnitude
direction = distanceVector.Unit
end
end
end
return nearestPlayer, distance, direction
end
RunService.Heartbeat:Connect(function()
local nearestPlayer, distance, direction = findNearestPlayer()
if nearestPlayer then
if distance = stopDistance then
humanoid:Move(direction)
else
humanoid:Move(Vector3.new())
end
end
end)
is it r6 or r15 bc i didn't understand what you said
also it dosent work
they dont do anything even though i get no errors i tried both r6 and r15 and it doesnt want to work
(pls reply)
(in the script) when pressing enter there are a couple of spaces and the text appears more to the right, right. Does it mater if the space is there? (same thing about the "end" does it mater if it is there?
is he able to like know that theres an object infront of him can go past stuff or just get stuck?
Trying to follow this using an enemy model I brought in from Blender. I got it to work for the R15 model but when I try and change the wording based on the model I am using I am getting a ton of errors so thinking I'm changing it wrong. Any tips on doing this for an injected model? This is the current error I am getting and it seems to not like Vector3.new: Move is not a valid member of MeshPart "Workspace.Enemies.Candy_Land.Hot_Choc_Mob_1.Plate". Thank you in advance
i cant do it its to hard for me :(
When testing with multiple players the script seems confused about which player/where to target. It seems to be trying to target both players at the same time instead of focusing on the single closest player
How would i add animations to this?
Hey, I have a Question can you make the dummy slower somehow?
I put everything correctly but the npc won’t move
Guys how do I make it so when you hit the NPC it starts chasing you?
how do i make it only start chasing you once the player gets within a certain radius of the enemy
how do you give the npc health i watched all parts but like no hp!!!!
Yo when I play it says “Character is. Not a valid member of Players “Players”
Thank you, this video was very helpful for me, but i'm curious about how can i make npcs go back to their spawn or other places after they stopped chasing player?
just set their root CFrame to the span location CFrame after the player is outside the distance.
idk how to do that tho
mine is not working,it says it dont identify the player
nice work i love it but its easyer if we could copy and past
can you make it stop after being to far away like the chasing is a range?
i wrote this exactly local distanceVector = (player.Character.HumanoidRootPart.Position - root.Position) but why does it gives an error. Workspace.Dummy.Humanoid.Script:20: attempt to index nil with 'Position' ..healp pls how?
Can you/anyone tell me how to set the primary part it dosent show it
You deserve more subs
AHHH IM SORRY HERE IT IS I JUST RELEASED IT
Help me the
Runservice.Heartbeat does not work
Hey how to type the "is less than" thing on keyboard? Idk how
For some reason when I added the script to my characters it doesn’t work, but the freemodel itself works, how do I fix this??
Edit: for some reason it does work but when my npc is made higher like by less than a stud it won’t work. It needs to be on the same ground level. Do you know a possible fox for this?
why does the end ()) has a wrong in it ?
Runservice.Heartbeat:Connect(function()
local nearestplayer, distance, direction = FindNearestPlayer()
if nearestplayer then
if distance = stopDistance then
humainoid:Move(direction)
else
humainoid:Move(Vector3.new())
end
end)
Do not talk to me until I have my morning coffee
thanks man it works, but do you have any way to make it that it avoids walls? it will chase me but it gets stuck in walls and other obstacles
Use robloxpathfinderservice
Hey! was rlly helpful, but for some reason my model came with humanoid but not humanoid root part? my model isnt r15 if that makes any difference. how do i get one?? it isnt in local
is there a way to make it so that the enemy not follow the player but instead a different part, I'm trying to do the basse thing from tbb
cant change Target distance and Stop distance
Can anyone help me? I tried this on my own model (a skeleton) which has a humanoid and is rigged properly and such. When I run this script, the skeleton just disappears for some reason. I tried pasting the script into a regular R15 rig and it works fine. Why doesn't it work on my skeleton?
Great tutorial though
thank you! :D
when it takes dmg the npc stops
Could you also make dummy that helps you in a battle
Is it a problem if my root part is the head? As im working with r6 as its easyer for animations.
can you create a monster that randomly attacks the player like Charles from "Choo Choo Charles" I understand that this game was made on a different game creation engine, but if possible, please do a tutorial on this
W video bro.