How to Make an Enemy NPC in Roblox Studio 2024!
HTML-код
- Опубликовано: 17 июл 2024
- Hey guys! In todays video I teach you how to make an Enemy NPC which chases you and attacks which can be used for many games and is very fun to play around with!
How to Make a Working ENEMY NPC in ROBLOX STUDIO!
SUBSCRIBE HERE! ➜ / @devmelonroblox
Be sure to hit the bell to turn on notifications!
Be sure to hit that like button!
Join my Roblox Group here: www.roblox.com/groups/9221251...
Join my discord here: / discord
#roblox #robloxscripting #robloxstudio
Timecodes
0:00 - Intro
0:49 - Rig
1:15 - Scripting
5:50 - Outro
How to Make a Working ENEMY NPC in ROBLOX STUDIO!How to Make a Working ENEMY NPC in ROBLOX STUDIO!f Игры
Thanks for watching! If you enjoyed make sure to like and also comment any suggestions below!
Can you make another video like this but with a more advanced ai? (e.g moving around parts) It would really help!
Is this for r6 too??
How to put script in description of a devmelon video tutorial
Yeeeeeee NICE VIDEO!
how do you make it to where it only chases you when in a certain range
script:
local NPC = script.Parent
local HumanoidRootPart = NPC.HumanoidRootPart
local MaxDistance = math.huge
local debounce = false
NPC.Humanoid.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and not debounce then
debounce = true
hit.Parent.Humanoid.Health -= 20
wait(1)
debounce = false
end
end)
while wait() do
local Players = game.Players:GetPlayers()
local closest
for i, plr in pairs(Players) do
if plr.Character and plr.Character:FindFirstChild("Humanoid") and plr.Character.Humanoid.Health > 0 then
local PlayerHumanoidRootPart = plr.Character.HumanoidRootPart
local Distance = (HumanoidRootPart.Position - PlayerHumanoidRootPart.Position).Magnitude
if not closest then
closest = PlayerHumanoidRootPart
end
if (HumanoidRootPart.Position - closest.Position).Magnitude > Distance then
closest = PlayerHumanoidRootPart
end
end
end
if closest and (HumanoidRootPart.Position - closest.Position).Magnitude
you saved me from finding a typo
OMG BRO TYSM I WAS TRYING TO SEARCH FOR A TYPO FOR 30 MIN BUT U SAVED ME
you just saved my keyboard bro 😂
Thank You!!!
THANK YOU SO MUCH BRO
Awesome video! Very Helpful and insightful
Glad it was helpful!
bruh finally a scipt that ACUALLY WORKED thx devmelon you helped me ALOT
the best of all the devs. love the work dev melon.
Thank you good sir
Ty so much this will help me a lot with the game that I'm making!❤
Can you make it so you get a leaderstat/variable when you kill it
devmelon thank you and i subscribe you. can you make a video about the hiding system from the enemy?
hey man i just came here to tell u that u that ur videos are useful, funny, and informative 🤓🤓🤓 but jokes aside u actually need more than 1.9k subs
Thanks
looking good, devmelon but it's better when it has attack animations so the enemy npc would be epic.
w video bro keep it up
Thanks!
Pleaseee, your videos are amazing but I had problems with this one, I used a rig from the toolbox of sonic exe and it only does damage when I touch him but he doesn’t chase.. what do I do. Was it bc I didn’t do the same rig as you or no..? I just really need to figure it out. Please and thank you🙏
Do you get any errors in your script?
@@devmelonrobloxno, but does it matter that I didn’t animate it and only copy and pasted the animate script?
0:25 IT ACTUALLY OOF MY BRAIN
You're fr one of the best Roblox Devs on RUclips right now.
Thanks!
thank you so much
I tried to do the chase script and after i was done it didnt work i do think it had something to do line 37 where you had “if Closest and (HumanoidRootPart.Position - Closest.Position).Magnitude
U have output windows opened? If you're not getting any errors, try putting print("test") in your script and see if it prints it.
what about adding an animation to it with cooldowns
How would i make it immortal or something like that bc if i put 2 they kill eachother
Thanks❤ and how do you replace the animations with different ones?
Yopu check the naimation script and there will be the run id in there youll find it
How do you make it so that multiple npcs dont kill each other but kill you only
You can name them all one name and where it checks for humanoid you can do if name ~= “name of npc”
@@devmelonrobloxcan u explain in more detail
I have a small question. I made a bunch of enemies but i don't want them to attack each other. However I don't really know how to fix that so could you make a video on how to make that?
Hey thanks for helping me with my game!
(your prob not going to see this) but how can i make it so the rig will chase after a player when its near them?
thanks for helping me with my game and i hope you have the time to respond
Hey! I think I. Will make a renewed version of the tutorial but there’s a way of checking the distance between the player and the dummy and checking if it’s lower
It’s quite hard to explain in comments
Oh wow you actually did respond! That’s fine though I will try my best!
@@DaLemonMonke158 ofc! Good luck with ur game
i made my own custom modle but it wont move it only follows my direction
Finally a script that works
I have looked trough so many tutorials and they have just been filled with people that cant speak properly and they also dont teach you anything they just say copy this script that I have linked in the description.
finaly someone explaining the script not just giving it to us to copy it thanksss
Thansk!
Someone help me it’s not working and the output says there are no errors
How would i be able to change the max distance, like if you were in a certain range it would follow you
You set the max distance on the script
@@devmelonroblox could i do local maxDistance = 10 ?
NO WAY! This is amazing. YOU literally read my mind. I was looking for the perfect video, and i think i found it! Thanks so much!
You're so welcome!
my npc just teleports at me for some reason. I even set its walkspeed to 10
Hey. idk if ur gonna see this but how do I make a custom model of the AI
devmelon: and it will-.. and it will allow-.. and it will allow you-... and it will allow the NPC to damage you.
😭
how would i make the detection range of the enemy lower (im making a castle i only want it to follow you when you go in)
if you know tell me
@@gdzh i found out but i can't put the full thing in the comments cuz it doesn't go through
@@bob-nh5qgok😢
my npc isnt moving any advice?
Same
It could be anchored, try unanchoring it
@@P4nM4nC0der ok
Look in the output and click the red it should take you to where the error is and fix it.
Hey devmelon! I watched your tutorial on how to make a difficult chart obby and it really helped! How did you learn code? I want to learn lua too but I cant learn it. Its too hard.
I think I learned by watching dev kings beginner tutorials
how do i make them respawn?
is it possible to make a safe zone where the npc wont go inside of?
I made multiple and the enemy NPCs hurt eachother pls help
It works well unless more than 1 npc is near eachother, then they will kill eachother
You can add a code so that it doesn’t follow if the persons name is npc and name all the npcs npc
@@devmelonrobloxhow to do that?
youre literally my roblox studio teacher lmao
Ahahah
fr
Thanks
Its not working idk what to do
how do I make it pathfinding???
Is there any way to add a range of agro for the rig so it does t attack me from anywhere?
change the math.huge on the MaxDistance into any number you want, that works for me
How do I make it so they don't FRICKIN ATTACK EACHOTHER
It worked the first time but when I colored it it stopped working
Make sure you spelled everything correctly
Hey devmelon ive tried typing the script that you did in the video and it doesn't seem to work so idk what i did wrong.
local NPC = script.Parent
local HumanoidRootPart = NPC.HumanoidRootPart
local MaxDistance = math.huge
local debounce = false
NPC.Humanoid.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and not debounce then
debounce = true
hit.Parent.Humanoid.Health -= 20
wait(1)
debounce = false
end
end)
while wait() do
local Players = game.Players:GetPlayers()
local closest
for i, plr in pairs(Players) do
if plr.Character and plr.Character:FindFirstChild("Humanoid") and plr.Character.Humanoid.Health > 0 then
local PlayerHumanoidRootPart = plr.Character.HumanoidRootPart
local Distance = (HumanoidRootPart.Position - PlayerHumanoidRootPart.Position).Magnitude
if not closest then
closest = PlayerHumanoidRootPart
end
if (HumanoidRootPart.Position - closest.Position).Magnitude > Distance then
closest = PlayerHumanoidRootPart
end
end
end
if closest and (HumanoidRootPart.Position - closest.Position).Magnitude
you can use a script of a zombie
plsssss help u didnt make a code for allowing him to die
dude its moving but not damaging me
Does this work in R6?
This Will Be My First Game
it didn't work I tried to fix it but it didn't work
please help me it didnt work my error is "humanoid is not a valid member of Model "Workspace.Grandpa" and yes the name of my rig is grandpa
Nvm i got it
@@DapperGapperTheYapper yesss!!!!
oye por que a mí no me funciona?
The animation isn't working for me, but I did as showed.
Which animation did you use?
@@devmelonroblox I just copy and pasted the one that was already in the rig
for some reason it did not work for me 😥
Do you get any errors?
@@devmelonroblox no it just does not work idk whats wrong with it
How we can kill them?
Vid starts at 2:00
Lol yes there are timeframes i think
1:56 yo were you ok?
Does this work with R6
Yes
It didnt work
right when i gain motivation again to work on my game
MY FREAKING (and im resisting to not say another word) STUDIO IS FREAKING BROKEN, BUILT IN PLUGINS DOES NOT WORK, I TRIED EVERYTHING AND NO CHANGES, NO ONE TALKS ABOUT IT ON THE DEVFORUM, AND BECAUSE OF THAT FREAKING TRUST THING I CANT FREAKING MAKE A POST
FRICK ROBLOX
Try uninstalling and reinstalling roblox studio!
@@devmelonroblox never though you will answer lol, i got a little bit mad, but yes i uninstalled it, didnt worked, so i manually deleted the entire roblox folder, did not worked too
@things4438 that’s really strange what
how do i can change distance?
change the math.huge on the MaxDistance into any number you want
@@malvinmahendra7356 hey, ty
didnt work :/
im sad now i needed it :(
Yours is the only good looking one
Do you get any errors?
but i hate R15 i use R6
did not work
Skill issue
@@HatInInternet you are trash
I have a better version of this were when the npc dead it does not attack and after 4 secs the npc destroys.
Script:
local NPC = script.Parent
local HumanoidRootPart = NPC.HumanoidRootPart
local Died = false
local MaxDistance = math.huge
local debounce = false
NPC.Humanoid.Died:Connect(function()
Died = true
wait(4)
NPC:Destroy()
end)
NPC.Humanoid.Touched:Connect(function(hit)
if Died == true then return end
if hit.Parent:FindFirstChild("Humanoid") and not debounce then
debounce = true
hit.Parent.Humanoid.Health -= 20
wait(1)
debounce = false
end
end)
while wait() do
local Players = game.Players:GetPlayers()
local closest
for i, plr in pairs(Players) do
if plr.Character and plr.Character:FindFirstChild("Humanoid") and plr.Character.Humanoid.Health > 0 then
local PlayerHumanoidRootPart = plr.Character.HumanoidRootPart
local Distance = (HumanoidRootPart.Position - PlayerHumanoidRootPart.Position).Magnitude
if not closest then
closest = PlayerHumanoidRootPart
end
if (HumanoidRootPart.Position - closest.Position).Magnitude > Distance then
closest = PlayerHumanoidRootPart
end
end
end
if closest and (HumanoidRootPart.Position - closest.Position).Magnitude
firist
Crazy
Lies never even moves
@@WildGamer0 bro at least tell me ur error that you get in the output💀
Instead of saying that I’m lying
@@devmelonroblox sorry I just got rly mad, the error was that it literally wasn’t even moving
@@WildGamer0 Do you get any erorr in the OUTPUT
Ohhh, it’s the same error that occurred for you at 5:01 I just didn’t watch it all I thought it was done when you play tested.
Apology’s😅🙏