8:16 for the blood effect to show when taken damage, instead of lowering humanoid health you can use a function called :TakeDamage() just use it on the humanoid and put the damage you want example: nearestPlayer.Character.Humanoid:TakeDamage(damage)
Thank you so much for these 2 tutorials! I was worried that I wouldn’t find a good and easy tutorial to make a enemy NPC like this for my game. I can’t tell you how much I appreciate it! You should make part 3 since your making a great job.
This is the first video or thing I've seen about Attributes in Roblox, it's super cool to see that it works with variables and properties from the scripts that we create, i could see that being super useful for later randomizing Enemy behavior or just randomizing other script behaviors in general, Also makes it easy to adjust settings and replace the settings to the desired ones accordingly
kinda rude bro, have you tried looking else for on how to load and play animations? its not hard. load the animation onto the animator then play in the same loop the damage loop is in.
@@Beij1ngCorn why would i encourage relying on one guy. theres more resources for you to rely on everywhere. for example yellow mustang. if you need encouragement to script then dont.
Amazing tutorials bro I have never touched and game creator in my life let alone code and I've now got a good start on my realistic zombie game that I want to create :D Thanks so much.
animation tutorial soon? 🥺 by far the best tutorial I've followed along so far, because you explain why we add certain things to help understand the mechanics. thank you sm!
wow new sub, i'm waiting for part 3!! You can also make that when the npc is chasing you, the camera shakes and gets a bit blurry, and make a walk animation and kill animation please
FULL SCRIPT: local RunService = game:GetService("RunService") local Players = game:GetService("Players") local humanoid = script.Parent local root = humanoid.Parent.PrimaryPart local targetDistance = script:GetAttribute("TargetDistance") local stopDistance = script:GetAttribute("StopDistance") local damage = script:GetAttribute("Damage") local attackDistance = script:GetAttribute("AttackDistance") local attackWait = script:GetAttribute("AttackWait") local lastAttack = tick() 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(direction) else humanoid:Move(Vector3.new()) end
if distance = attackWait then lastAttack = tick() nearestPlayer.Character.Humanoid.Health -= damage end end end)
Hey, could you be able to add intense camera shakes as soon as the enemy starts chasing you around? You could use camera shaker module for it! I need it because I saw no-one was making tutorials about it... But hey, waiting for part 3 of the tutorial!!!
@@Seer_Verse somewhere in the scrip you have to add a remote event that goes to the client, and when the client receives it, you can use the "Camera Shaker" module script from the toolbox. Search up a tutorial on the camera shaker module if you can't figure it out.
Idea for part 3!: show us how to make it chase within a certain distance and also have a separate animation for chase and walk for the monster also a screen shake for when its chasing you!
I need to make an enemy NPC that you can fight back and defend yourself from but I need to know how to script it to chase you only after you punch it instead of it chasing you if you get close to it. But so far this video is helping me
Hi, I’m a huge fan from how you explain these videos what are spectacular but my r15 npc by a verified creator even yours wouldn’t attack or cause damage on me. Do you have any advice to fix this situation?
Hi there! I'm not exactly sure what the problem may be; are there any errors that pop up in the output panel when you run the game? I'm surprised mine didn't work, but other people are having similar issues it seems. What I would do is try adding print statements to the code in order to figure out if the code is attempting to run at all and find what parts may be causing the issue. Is it at least chasing the player?
Since the script within the NPC loops through the players within the game to determine its target, it will only target player's characters. So the NPC shouldn't damage other NPCs.
When is part 3 coming? You said that it was coming “this weekend” a month ago. Me personally, I don’t think that an animation script takes this long. Please hurry up with part 3. Thank you for your time.
I have a question, I want to make it where once you finish a certain dialogue with the NPC then it starts attacking the player after a few seconds, but I dont know how to do that, does anyone know how?
Hi there! I'm curious about how you implemented the dialogue, is it with Roblox's dialogue objects? My first thought would be to add a bool attribute named "aggressive", and have it that the NPC only chases and attacks players when that value is true. Every physics frame it would check the value and only run the rest of the code if it was true. You would have to find a way for code to run after the dialogue ended, wait however seconds you wanted, then set the attribute to true. I think dialogue objects have an event for when dialogue choices are selected. The only issue is that doing that would make it aggressive for everyone if done on the server, so If that's not what you're intending I would have to think a little bit more on the subject. Sorry for my rambling, I hope you figure it out!
@@mrmodulescript yeah its with robloxs built in dialog adder, but I apologize. I am not a game developer or anything, im just making a stupid joke game lmao, I am so dumb i dont know what half the things you said were.. lol
This was great while it lasted! I got some feedback on this script from ChatGPT and it loved it except it's easy to exploiters to change the attributes of the enemy ai
hey, I used this script on my own model and it doesn't work. first it worked but only the humanoidrootpart worked then I rigged the model and now nothing moves
The speed can be changed by clicking on the humanoid object within the model and changing the "WalkSpeed" property. The range can be changed by clicking on the EnemyController script and changing the AttackDistance attribute (scroll down to the bottom of the properties tab to find the attributes).
Would this code run well with multiple enemies? I'd imagine using heartbeat with 50+ enemies would cause performance issues. Any solution, or could you do a video on making performant enemies
the code strangely doesnt work for me, when i try to test it as i have finished the tutorial. i still get a error message saying "Workspace.Dummy.Humanoid.EnemyController:49: attempt to compare number
Hello sir, I have a question. I am using this npc in my Roman game but there is 1 problem. The shield I have doesn't work against the damage of the npc. Is it possible to fix this?
Hi there, if you are referring to force fields not blocking damage from the NPC, it's because I changed the health of the humanoid directly (humanoid.Health -= damage) rather than using the TakeDamage method of the humanoid (humanoid:TakeDamage(damage)) That was a mistake on my part and will be talked about and fixed in my next tutorial as well. Hope this solves your problem!
@@mrmodulescript Its actually not the spawnprotection, but the Roman shield I designed. It does not block the npcs damage. Is that fixed in the same way or different?
@@hoierdiehoi8142 Ah, sorry for the confusion. That would be fixed in a different way. With this enemy NPC specifically, you would have to add a check in the NPC script where it looks to see if the player it is attacking is holding the shield (and has it activated if that's how your shield works) before it deals damage. How that check would work is up to you, but if the shield is a tool a character wields, a basic idea would be to add a Character:FindFirstChild("ShieldNameHere") and if it finds the shield, then the player is holding the shield and shouldn't take damage.
@@mrmodulescript When u click right mouse button the shield activates. Is it possible to make it so that when u point the shield at the npc there will be no damage but when pointed away the npcs will just hit you? (maybe im asking a little to much now)
wheres the next tutorial! Can you show us how to make a hit animation, and can you make it so the enemy wanders because i made a walking animation for it
can it do animation when it hits the player? i want to make cave horror game based on one really good horror movie and the things that lived in the cave was blind and got really good animations, can you also make it blind too? it would be really helpful
8:16 for the blood effect to show when taken damage, instead of lowering humanoid health you can use a function called :TakeDamage() just use it on the humanoid and put the damage you want
example: nearestPlayer.Character.Humanoid:TakeDamage(damage)
I did that before so i knew it before seeing your comment 🤣🤣🤣🤣🤣🤣🤣🤣🤣🤣🤣🤣🤣🤣🤣🤣
@@JerielordPlays that emoji spam though..
Thank you so much for these 2 tutorials! I was worried that I wouldn’t find a good and easy tutorial to make a enemy NPC like this for my game. I can’t tell you how much I appreciate it! You should make part 3 since your making a great job.
This is the first video or thing I've seen about Attributes in Roblox, it's super cool to see that it works with variables and properties from the scripts that we create, i could see that being super useful for later randomizing Enemy behavior or just randomizing other script behaviors in general, Also makes it easy to adjust settings and replace the settings to the desired ones accordingly
Thank you so much! Im learning so many things and starting to understand kind of what im doing. Cant wait fo part 3!!!
I'm glad to hear you're benefiting from these videos! Part 3 is currently in the works!
@@mrmodulescript thank you so much. Im supper excited
@@mrmodulescript hi, im actually making a game and the animation is really difficult, the part 3 is finish ?
PS: amazing the part one and two.
@@mrmodulescript 7 months now... still waiting...
@@mrmodulescript rip part 3
When is part 3? Your doing good work
Thank you so much! Your videos are super helpful and easy to understand/follow along! 💖
Please do part 3! these vids are really helpful and maybe adding an hp bar to the npc as well?
Did it. Just released. HP bar will be coming in a future tutorial (not sure which part yet)
You earn this man congrats thanks for the video! Cant wait for part 3. Also can make it like attacks the players instead of the other npc nearby
part 3 please, the existing tutorials were helpful and I really need to know how to animate the NPC enemy for my game
Finishing it up as I'm typing this, expect it soon! Thanks for your kind words!
@@mrmodulescript when
kinda rude bro, have you tried looking else for on how to load and play animations? its not hard. load the animation onto the animator then play in the same loop the damage loop is in.
@@Beij1ngCorn why would i encourage relying on one guy. theres more resources for you to rely on everywhere. for example yellow mustang. if you need encouragement to script then dont.
@@Beij1ngCorn you did not say " you do not have to encourage me"
Amazing.(Also for the next tutorial could you make the Enemy NPC animated? or an R6 Version?)
Yep! That's the plan :)
You can put the script on the r6 model and make sure that the humanoidrootpart is unanchored
im trying to make a game rn the next tutorial on animating the NPC will be so cool thanks so much best tutorial i found
I'm glad to hear that, I hope your game turns out great!
Great tutorial, you should make more tutorials like this series
It just keeps getting better.
Thanks for this. This is so useful! keep uploading more coding tutorials please.
Amazing tutorials bro I have never touched and game creator in my life let alone code and I've now got a good start on my realistic zombie game that I want to create :D Thanks so much.
Happy to hear that!
animation tutorial soon? 🥺 by far the best tutorial I've followed along so far, because you explain why we add certain things to help understand the mechanics. thank you sm!
son he''s not coming back ;-;
@@gamingforfun5232 yea ;-;
You earned a sub this is really helpful and taught me a lot thank you!
great work!
Thanks! I really appreciate your kind words!
wow new sub, i'm waiting for part 3!! You can also make that when the npc is chasing you, the camera shakes and gets a bit blurry, and make a walk animation and kill animation please
Earn a new sub looking forward to more of the tutorials
Thanks! Plenty more to come!
this guy is a legend for this
Underrated like fr
yay part 2
ikr
Hello I am here for part 3 :)
FULL SCRIPT:
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local humanoid = script.Parent
local root = humanoid.Parent.PrimaryPart
local targetDistance = script:GetAttribute("TargetDistance")
local stopDistance = script:GetAttribute("StopDistance")
local damage = script:GetAttribute("Damage")
local attackDistance = script:GetAttribute("AttackDistance")
local attackWait = script:GetAttribute("AttackWait")
local lastAttack = tick()
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(direction)
else
humanoid:Move(Vector3.new())
end
if distance = attackWait then
lastAttack = tick()
nearestPlayer.Character.Humanoid.Health -= damage
end
end
end)
People like you are the besy
man accidentally put a link in the script lmao
@@theRealTwiceler it actually leads to a site lmao
@@EchoOnLive Did you unanchor the humanoid root part?
it doesn't follow me and shows me this error : Workspace.Spider.Humanoid.EnemyController:43: attempt to compare nil
Are you going to make a part 3? I've found this very helpful :)
Part 3 will be out this weekend! Thanks for the feedback!
@MrModuleScript Great! These videos have been entertaining and informative thanks for the work
@@mrmodulescript hey I saw you said this weekend but it never came out. Do you have an estimate?
...
He only has 4 vids... don't mean to skip to the dark stuff, maybe another reason.
Can't wait for part 3!
Don't have to anymore, just released it!
Noooo this series was so helpful you have to make part 3 😭
bro we need part 3 man please we need it we need it ur our legend
I got you, released it just now, my bad for the wait
great vid bro! keep it going
Hey, could you be able to add intense camera shakes as soon as the enemy starts chasing you around? You could use camera shaker module for it! I need it because I saw no-one was making tutorials about it... But hey, waiting for part 3 of the tutorial!!!
fire a remote event to the client from the enemy when it starts chasing you and stops chasing you
@@DanCodes how do you make the camera shake?
@@Seer_Verse somewhere in the scrip you have to add a remote event that goes to the client, and when the client receives it, you can use the "Camera Shaker" module script from the toolbox. Search up a tutorial on the camera shaker module if you can't figure it out.
@@DanCodes K thanks
This channel is going to be awesome I know it
we need to get him to 1.00k subs he's underrated he needs to start making money
he hasnt posted in 8 months
My bad, part 3 is out now, and I hit that milestone! Insane!
Excellent info, easy and simple.
Idea for part 3!: show us how to make it chase within a certain distance and also have a separate animation for chase and walk for the monster also a screen shake for when its chasing you!
Btw this would rlly help me and people making mimic themed games!
i hop u continue growing
I need to make an enemy NPC that you can fight back and defend yourself from but I need to know how to script it to chase you only after you punch it instead of it chasing you if you get close to it. But so far this video is helping me
love it and um can you maybe explain what exactly everything does and the script
Cant wait for part 3
Hi, I’m a huge fan from how you explain these videos what are spectacular but my r15 npc by a verified creator even yours wouldn’t attack or cause damage on me. Do you have any advice to fix this situation?
Hi there! I'm not exactly sure what the problem may be; are there any errors that pop up in the output panel when you run the game? I'm surprised mine didn't work, but other people are having similar issues it seems. What I would do is try adding print statements to the code in order to figure out if the code is attempting to run at all and find what parts may be causing the issue. Is it at least chasing the player?
@@mrmodulescript hello, I did print statements and there wasn’t any errors popping up but the npc would follow but not cause dmg
Great, much appreciated on the video
Do you think a part 3 is coming soon? I think it would be great! Your tutorials are awesome!❤❤❤
Ik
thank u so much this is so helpful ^^
This is really good! But I have a question, when duplicating the NPC does it damage the other NPC?
Since the script within the NPC loops through the players within the game to determine its target, it will only target player's characters. So the NPC shouldn't damage other NPCs.
@@mrmodulescript Thanks!
@@mrmodulescript hey, is there a way to make the npc respawn after he dies
@@SETRlX just insert a respawn script, in the toolbox, search 'respawning dummy' and take the script out of it and into your killer npc
This is great! When is the next one happening?
great tutorial!!
how do you make it so the enemy have a custom idle and walk animation?
I was actually working on that exact thing just a bit ago! That will be the topic for the next part of the tutorial. Which should be out soon.
@@mrmodulescript thank you for this, it helps me a lot
What would happen if there was a wall between you and the enemy
For me it doesn't actually do any damage I've copied the script exactly any tips
When is part 3 coming? You said that it was coming “this weekend” a month ago. Me personally, I don’t think that an animation script takes this long. Please hurry up with part 3. Thank you for your time.
Sorry about that, multiple editing issues popped up and I became very busy with classes. It just released now!
Sooo... This came out over a year ago now. I guess this means there isn't a part 3?
There is now :)
I have a question, I want to make it where once you finish a certain dialogue with the NPC then it starts attacking the player after a few seconds, but I dont know how to do that, does anyone know how?
Hi there! I'm curious about how you implemented the dialogue, is it with Roblox's dialogue objects?
My first thought would be to add a bool attribute named "aggressive", and have it that the NPC only chases and attacks players when that value is true. Every physics frame it would check the value and only run the rest of the code if it was true. You would have to find a way for code to run after the dialogue ended, wait however seconds you wanted, then set the attribute to true. I think dialogue objects have an event for when dialogue choices are selected.
The only issue is that doing that would make it aggressive for everyone if done on the server, so If that's not what you're intending I would have to think a little bit more on the subject. Sorry for my rambling, I hope you figure it out!
@@mrmodulescript yeah its with robloxs built in dialog adder, but I apologize. I am not a game developer or anything, im just making a stupid joke game lmao, I am so dumb i dont know what half the things you said were.. lol
When is part 3? i really need it and i hAve been waiting so long thank you!
Thank you so much this was so helpful,can you please make a attacking shark with smooth movement?
I am waiting for sooo long alr
great video, part 3?
This was great while it lasted! I got some feedback on this script from ChatGPT and it loved it except it's easy to exploiters to change the attributes of the enemy ai
does anyone know why my character doesn't take damage? I followed the instructions and read it twice but it just follows me around.
Hi. I was wondering. Probably In a part 4 if you could do projectiles or magic attacks.
Can you make a part 3 of how to animate the npcs walk animation using moon animatior idk please
I did, but not using moon animator, I used the basic animation editor instead.
hey, I used this script on my own model and it doesn't work. first it worked but only the humanoidrootpart worked then I rigged the model and now nothing moves
You Should Make A Part 3 Where It Has An Animation
How do i change the range on the model you made? also how do i change the speed?
The speed can be changed by clicking on the humanoid object within the model and changing the "WalkSpeed" property. The range can be changed by clicking on the EnemyController script and changing the AttackDistance attribute (scroll down to the bottom of the properties tab to find the attributes).
Would this code run well with multiple enemies? I'd imagine using heartbeat with 50+ enemies would cause performance issues. Any solution, or could you do a video on making performant enemies
the code strangely doesnt work for me, when i try to test it as i have finished the tutorial. i still get a error message saying "Workspace.Dummy.Humanoid.EnemyController:49: attempt to compare number
bro you were so close to escaping the MAD DUMMY (undertale refrence?) otherwise good tutorial sequel (UNDERTALE 2 REFRENCE?!)
Thank you 💝
Hello sir, I have a question. I am using this npc in my Roman game but there is 1 problem. The shield I have doesn't work against the damage of the npc. Is it possible to fix this?
Hi there, if you are referring to force fields not blocking damage from the NPC, it's because I changed the health of the humanoid directly (humanoid.Health -= damage) rather than using the TakeDamage method of the humanoid (humanoid:TakeDamage(damage))
That was a mistake on my part and will be talked about and fixed in my next tutorial as well.
Hope this solves your problem!
@@mrmodulescript Thank you! Looking forward to part 3!
@@mrmodulescript Its actually not the spawnprotection, but the Roman shield I designed. It does not block the npcs damage. Is that fixed in the same way or different?
@@hoierdiehoi8142 Ah, sorry for the confusion. That would be fixed in a different way. With this enemy NPC specifically, you would have to add a check in the NPC script where it looks to see if the player it is attacking is holding the shield (and has it activated if that's how your shield works) before it deals damage. How that check would work is up to you, but if the shield is a tool a character wields, a basic idea would be to add a Character:FindFirstChild("ShieldNameHere") and if it finds the shield, then the player is holding the shield and shouldn't take damage.
@@mrmodulescript When u click right mouse button the shield activates. Is it possible to make it so that when u point the shield at the npc there will be no damage but when pointed away the npcs will just hit you? (maybe im asking a little to much now)
Is a part 3 going to be coming out?
Hello amazing video but is there a way to use this for my own model?
How do you make the Npc respawn?
hii...thank you so much XD its working...but can you make tutorial how to add gun
Hi you should make part 3, Can you please make part 3 ?!
Oh and in the part 3 can you make the animation
Could you please make one for when it is provoked that would be awesome?! Otherwise this is super awesome and many thanks!!
finnaly know how to make a enemy now
Just me patiently waiting for a part 3
Thx man 😊
Hey i have question, How can I change the skin of the dummy?
Right click your dummy, the insert object > Body colors > Go to properties, you can change colors or give it a texture id
anyone know how to add parts to the "dummy" model? (decorate it)
wheres the next tutorial!
Can you show us how to make a hit animation,
and can you make it so the enemy wanders because i made a walking animation for it
so how would i make it return to its original position ??
can it do animation when it hits the player? i want to make cave horror game based on one really good horror movie and the things that lived in the cave was blind and got really good animations, can you also make it blind too? it would be really helpful
Help, I have no idea why but everything is one-hitting me??
Epic!
Great!!
How to make Enemy stop following you after a certain distance???
but amazing video
how can you make it so the npc looks towards the target player?
please part 3 this is the only good tutorial
Out now, glad to hear you like the series!
how do u make it damageable like i can shoot it or something
Is there a possibility to make a stun taser gun to stop the ai for like 5 seconds
everytime i kill it it still attacks me?? pls help someone
tysm bro
can you make a part 3 and also you have earned a sub
Part 3 out now
is it pathfinding like it doesnt get stuck on a wall or a object in its way?
Unfortunately, no, that's a bit harder to implement, but it might be added in a future tutorial!
will there be a Part 3?
how can we let him respawn if he go to far from his spawnpoint
can you make it wander around the map next tutorial in part 3?? instead of it just sitting there
how to add animation?
You should make part 3!
Just did, sorry for the wait!