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
  • ИгрыИгры

Комментарии • 154

  • @devmelonroblox
    @devmelonroblox  4 месяца назад +9

    Thanks for watching! If you enjoyed make sure to like and also comment any suggestions below!

    • @tuh_reptile
      @tuh_reptile 2 месяца назад +1

      Can you make another video like this but with a more advanced ai? (e.g moving around parts) It would really help!

    • @silkesolke
      @silkesolke 2 месяца назад

      Is this for r6 too??

    • @fevineslegend
      @fevineslegend 2 месяца назад

      How to put script in description of a devmelon video tutorial

    • @JumpyMan204
      @JumpyMan204 Месяц назад +1

      Yeeeeeee NICE VIDEO!

    • @The_Ace_Debate
      @The_Ace_Debate Месяц назад

      how do you make it to where it only chases you when in a certain range

  • @BlueWithaFruit
    @BlueWithaFruit 4 месяца назад +68

    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

  • @deathdoesroblox
    @deathdoesroblox 4 месяца назад +4

    Awesome video! Very Helpful and insightful

  • @mr_angel_potat
    @mr_angel_potat 2 месяца назад +2

    bruh finally a scipt that ACUALLY WORKED thx devmelon you helped me ALOT

  • @mrgoodman7837
    @mrgoodman7837 4 месяца назад +1

    the best of all the devs. love the work dev melon.

  • @SunsetVR21
    @SunsetVR21 3 месяца назад +1

    Ty so much this will help me a lot with the game that I'm making!❤

  • @WhartonProject
    @WhartonProject 4 месяца назад +3

    Can you make it so you get a leaderstat/variable when you kill it

  • @greemp
    @greemp 2 месяца назад +2

    devmelon thank you and i subscribe you. can you make a video about the hiding system from the enemy?

  • @JumpyMan204
    @JumpyMan204 Месяц назад +1

    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

  • @TizianoNicolasGamer100
    @TizianoNicolasGamer100 5 дней назад

    looking good, devmelon but it's better when it has attack animations so the enemy npc would be epic.

  • @Tuxedox
    @Tuxedox 4 месяца назад +4

    w video bro keep it up

  • @TTVtreekoVr
    @TTVtreekoVr 22 дня назад +2

    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🙏

    • @devmelonroblox
      @devmelonroblox  21 день назад

      Do you get any errors in your script?

    • @TTVtreekoVr
      @TTVtreekoVr 17 дней назад +1

      @@devmelonrobloxno, but does it matter that I didn’t animate it and only copy and pasted the animate script?

  • @zevkellygaintano3176
    @zevkellygaintano3176 14 часов назад +1

    0:25 IT ACTUALLY OOF MY BRAIN

  • @clopheritearchive
    @clopheritearchive 11 дней назад +1

    You're fr one of the best Roblox Devs on RUclips right now.

  • @deathreaper4200
    @deathreaper4200 4 месяца назад +1

    thank you so much

  • @Mr.Outlet1
    @Mr.Outlet1 Месяц назад +2

    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

    • @HatInInternet
      @HatInInternet 9 дней назад

      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.

  • @kadsian539
    @kadsian539 2 месяца назад +2

    what about adding an animation to it with cooldowns

  • @MasterGamer_122YT
    @MasterGamer_122YT 3 месяца назад +1

    How would i make it immortal or something like that bc if i put 2 they kill eachother

  • @BushiX5
    @BushiX5 2 месяца назад +2

    Thanks❤ and how do you replace the animations with different ones?

    • @devmelonroblox
      @devmelonroblox  2 месяца назад +1

      Yopu check the naimation script and there will be the run id in there youll find it

  • @ERICNETIC_pubgm
    @ERICNETIC_pubgm Месяц назад +3

    How do you make it so that multiple npcs dont kill each other but kill you only

    • @devmelonroblox
      @devmelonroblox  Месяц назад

      You can name them all one name and where it checks for humanoid you can do if name ~= “name of npc”

    • @EricChawira
      @EricChawira Месяц назад

      @@devmelonrobloxcan u explain in more detail

  • @StupidMiners
    @StupidMiners 2 месяца назад

    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?

  • @DaLemonMonke158
    @DaLemonMonke158 Месяц назад +2

    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

    • @devmelonroblox
      @devmelonroblox  Месяц назад

      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

    • @devmelonroblox
      @devmelonroblox  Месяц назад

      It’s quite hard to explain in comments

    • @DaLemonMonke158
      @DaLemonMonke158 Месяц назад +2

      Oh wow you actually did respond! That’s fine though I will try my best!

    • @devmelonroblox
      @devmelonroblox  Месяц назад

      @@DaLemonMonke158 ofc! Good luck with ur game

  • @KingLlama432
    @KingLlama432 2 месяца назад +1

    i made my own custom modle but it wont move it only follows my direction

  • @digipug
    @digipug 3 месяца назад

    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.

  • @Akino_Artist
    @Akino_Artist 2 месяца назад +2

    finaly someone explaining the script not just giving it to us to copy it thanksss

  • @Igrowtreesforlife
    @Igrowtreesforlife Месяц назад +1

    Someone help me it’s not working and the output says there are no errors

  • @BlueWithaFruit
    @BlueWithaFruit 4 месяца назад +1

    How would i be able to change the max distance, like if you were in a certain range it would follow you

    • @devmelonroblox
      @devmelonroblox  4 месяца назад +1

      You set the max distance on the script

    • @Rushing-know
      @Rushing-know 3 месяца назад

      @@devmelonroblox could i do local maxDistance = 10 ?

  • @TheGuyThatKnewThe
    @TheGuyThatKnewThe 4 месяца назад +3

    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!

  • @thecubeheadguy6747
    @thecubeheadguy6747 3 месяца назад

    my npc just teleports at me for some reason. I even set its walkspeed to 10

  • @LincZz
    @LincZz 3 дня назад

    Hey. idk if ur gonna see this but how do I make a custom model of the AI

  • @JumpyMan204
    @JumpyMan204 Месяц назад +1

    devmelon: and it will-.. and it will allow-.. and it will allow you-... and it will allow the NPC to damage you.

  • @bob-nh5qg
    @bob-nh5qg Месяц назад +1

    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)

    • @gdzh
      @gdzh 20 дней назад

      if you know tell me

    • @bob-nh5qg
      @bob-nh5qg 20 дней назад

      @@gdzh i found out but i can't put the full thing in the comments cuz it doesn't go through

    • @gdzh
      @gdzh 20 дней назад

      @@bob-nh5qgok😢

  • @coreonstyx
    @coreonstyx Месяц назад +6

    my npc isnt moving any advice?

    • @AxelResendez546
      @AxelResendez546 17 дней назад +2

      Same

    • @P4nM4nC0der
      @P4nM4nC0der 15 дней назад +2

      It could be anchored, try unanchoring it

    • @coreonstyx
      @coreonstyx 15 дней назад +1

      @@P4nM4nC0der ok

    • @Lil_Ninja
      @Lil_Ninja 11 часов назад

      Look in the output and click the red it should take you to where the error is and fix it.

  • @ExtremeShadow
    @ExtremeShadow 4 месяца назад +2

    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.

    • @devmelonroblox
      @devmelonroblox  4 месяца назад +1

      I think I learned by watching dev kings beginner tutorials

  • @autorade69420
    @autorade69420 2 месяца назад +1

    how do i make them respawn?

  • @SafeOfArsenal
    @SafeOfArsenal 7 дней назад

    is it possible to make a safe zone where the npc wont go inside of?

  • @BushiX5
    @BushiX5 2 месяца назад

    I made multiple and the enemy NPCs hurt eachother pls help

  • @The_ShyGuy64
    @The_ShyGuy64 3 месяца назад +1

    It works well unless more than 1 npc is near eachother, then they will kill eachother

    • @devmelonroblox
      @devmelonroblox  3 месяца назад +1

      You can add a code so that it doesn’t follow if the persons name is npc and name all the npcs npc

    • @autorade69420
      @autorade69420 2 месяца назад

      @@devmelonrobloxhow to do that?

  • @2lmao2
    @2lmao2 4 месяца назад +2

    youre literally my roblox studio teacher lmao

  • @HanaaMajdrazane
    @HanaaMajdrazane Месяц назад

    Thanks

  • @gigamario9056
    @gigamario9056 3 месяца назад

    Its not working idk what to do

  • @jorgeahernandez1212
    @jorgeahernandez1212 Месяц назад

    how do I make it pathfinding???

  • @ZachariasTheGreat_
    @ZachariasTheGreat_ 2 месяца назад

    Is there any way to add a range of agro for the rig so it does t attack me from anywhere?

    • @malvinmahendra7356
      @malvinmahendra7356 2 месяца назад

      change the math.huge on the MaxDistance into any number you want, that works for me

  • @Random_Idiot69420
    @Random_Idiot69420 23 дня назад

    How do I make it so they don't FRICKIN ATTACK EACHOTHER

  • @daveiscool24
    @daveiscool24 Месяц назад +1

    It worked the first time but when I colored it it stopped working

    • @devmelonroblox
      @devmelonroblox  Месяц назад

      Make sure you spelled everything correctly

  • @bananakid8270
    @bananakid8270 3 месяца назад +1

    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.

    • @xlives23
      @xlives23 6 дней назад

      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

  • @thatonehelperdude-vj8rp
    @thatonehelperdude-vj8rp 4 месяца назад +1

    you can use a script of a zombie

  • @mrbob7891
    @mrbob7891 14 дней назад +1

    plsssss help u didnt make a code for allowing him to die

  • @deathreaper4200
    @deathreaper4200 4 месяца назад

    dude its moving but not damaging me

  • @NaiveSchmidt
    @NaiveSchmidt Месяц назад

    Does this work in R6?

  • @haytamelmoutawakkil7789
    @haytamelmoutawakkil7789 День назад

    This Will Be My First Game

  • @terezaopatril8966
    @terezaopatril8966 2 месяца назад

    it didn't work I tried to fix it but it didn't work

  • @DapperGapperTheYapper
    @DapperGapperTheYapper 14 дней назад

    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

  • @gabrielafierrolara9866
    @gabrielafierrolara9866 3 дня назад

    oye por que a mí no me funciona?

  • @declanconway7966
    @declanconway7966 2 месяца назад +1

    The animation isn't working for me, but I did as showed.

    • @devmelonroblox
      @devmelonroblox  2 месяца назад

      Which animation did you use?

    • @declanconway7966
      @declanconway7966 2 месяца назад

      @@devmelonroblox I just copy and pasted the one that was already in the rig

  • @ImNinjaNick
    @ImNinjaNick Месяц назад +2

    for some reason it did not work for me 😥

    • @devmelonroblox
      @devmelonroblox  Месяц назад

      Do you get any errors?

    • @ImNinjaNick
      @ImNinjaNick Месяц назад +1

      @@devmelonroblox no it just does not work idk whats wrong with it

  • @user-smal_-games
    @user-smal_-games Месяц назад

    How we can kill them?

  • @Nick-445.
    @Nick-445. 3 месяца назад +1

    Vid starts at 2:00

    • @devmelonroblox
      @devmelonroblox  3 месяца назад

      Lol yes there are timeframes i think

  • @BiscuitIsUrFriend
    @BiscuitIsUrFriend Месяц назад

    1:56 yo were you ok?

  • @That_1Pumpkin
    @That_1Pumpkin 2 месяца назад +1

    Does this work with R6

  • @theawesomechannel6563
    @theawesomechannel6563 3 месяца назад

    It didnt work

  • @things4438
    @things4438 20 дней назад

    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

    • @devmelonroblox
      @devmelonroblox  20 дней назад

      Try uninstalling and reinstalling roblox studio!

    • @things4438
      @things4438 20 дней назад

      @@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

    • @devmelonroblox
      @devmelonroblox  20 дней назад

      @things4438 that’s really strange what

  • @IlIIlIlllIlII
    @IlIIlIlllIlII 2 месяца назад

    how do i can change distance?

    • @malvinmahendra7356
      @malvinmahendra7356 2 месяца назад

      change the math.huge on the MaxDistance into any number you want

    • @IlIIlIlllIlII
      @IlIIlIlllIlII 2 месяца назад

      @@malvinmahendra7356 hey, ty

  • @CarLover33384
    @CarLover33384 4 месяца назад +1

    didnt work :/

  • @chaseavery2586
    @chaseavery2586 Месяц назад

    but i hate R15 i use R6

  • @MeteoritePlays
    @MeteoritePlays Месяц назад +1

    did not work

  • @thatyoutubeguy-md2ws
    @thatyoutubeguy-md2ws 11 дней назад +1

    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

  • @zmigal
    @zmigal 4 месяца назад +2

    firist

  • @WildGamer0
    @WildGamer0 19 дней назад

    Lies never even moves

    • @devmelonroblox
      @devmelonroblox  18 дней назад +1

      @@WildGamer0 bro at least tell me ur error that you get in the output💀

    • @devmelonroblox
      @devmelonroblox  18 дней назад +1

      Instead of saying that I’m lying

    • @WildGamer0
      @WildGamer0 18 дней назад +1

      @@devmelonroblox sorry I just got rly mad, the error was that it literally wasn’t even moving

    • @devmelonroblox
      @devmelonroblox  18 дней назад +1

      @@WildGamer0 Do you get any erorr in the OUTPUT

    • @WildGamer0
      @WildGamer0 18 дней назад +1

      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😅🙏