Create An NPC That Can Attack With A Weapon In Roblox

แชร์
ฝัง
  • เผยแพร่เมื่อ 29 ต.ค. 2024

ความคิดเห็น • 229

  • @Mert-jv1je
    @Mert-jv1je 2 ปีที่แล้ว +2

    Thanks finally someone has made a tutorial on how to make an npc to draw his sword. You've just earned another subscriber

  • @user-kr8kx7lm3r
    @user-kr8kx7lm3r ปีที่แล้ว +1

    Excellent vid... I kept wondering how to make this and found stuff on the tool box.. but this vid actually helped me

  • @innergameroblox
    @innergameroblox 3 ปีที่แล้ว +8

    Didn't work at first try but i managed to fix it using output, Thank you!

    • @BossKnight
      @BossKnight 3 ปีที่แล้ว

      how did you fix it exactly? cause mine isn't working either

    • @innergameroblox
      @innergameroblox 3 ปีที่แล้ว

      @@BossKnight Check the output for errors and fix them, that's what i did but you need to have some scripting knowledge to be able to fix these errors.

    • @BossKnight
      @BossKnight 3 ปีที่แล้ว

      @@innergameroblox i found the problem, i just mispelled players and char

  • @computerheadman1601
    @computerheadman1601 2 ปีที่แล้ว

    man, i spend a good 3 days scratching my head thinking why doesnt my mesh rig moove with the script, and after this video i now know there is a small anchored part inside the rig models, thanks for the tutorial dude im subscribed now

  • @Takuma_FN
    @Takuma_FN 2 ปีที่แล้ว +3

    This helped me a lot. Thank you!

  • @themastershark7696
    @themastershark7696 2 ปีที่แล้ว

    Thank you i was making a new roblox game and I found this video really helpful!

  • @guilhermefernandes2630
    @guilhermefernandes2630 ปีที่แล้ว +3

    Here you have the Attack script:
    local char = script.Parent
    local hrp = char:WaitForChild("HumanoidRootPart")
    local hum = char:WaitForChild("Humanoid")
    local sword = char:WaitForChild("ClassicSword")
    local be = char:WaitForChild("ToolBe")
    local players = game:GetService("Players")
    local function finClosestPlayersHrp(myHrp, distOfInt)
    local closestHrp = nil
    for _, ply in pairs(players:GetChildren()) do
    local plyChar = ply.Character or ply.CharacterAdded:Wait()
    local plyHrp = plyChar:WaitForChild("HumanoidRootPart")
    local tmpDis = (myHrp.Position - plyHrp.Position).Magnitude
    if tmpDis < distOfInt then
    closestHrp = plyHrp
    distOfInt = tmpDis
    end
    end
    return closestHrp
    end
    while wait(.1) do
    local closestHrp = finClosestPlayersHrp(hrp, 20)
    if closestHrp then
    hum:EquipTool (sword)
    wait(1)
    while closestHrp.Parent.Humanoid.Health > 0 do
    hum:MoveTo(closestHrp.Position, closestHrp)
    be:Fire()
    wait(.2)
    end
    hum:UnequipTools()
    else
    hum:UnequipTools()
    end
    end

  • @avapatdu6828
    @avapatdu6828 ปีที่แล้ว

    It actually worked, woah thanks simtek!

  • @Moruko_desu
    @Moruko_desu ปีที่แล้ว +1

    Hi! This video is very helpful! Thank you. But i have a question, does this works with staff or gun ?

  • @itsazerty9493
    @itsazerty9493 3 ปีที่แล้ว +3

    Thanks , i really needed that 😊

  • @REDPOTATO40
    @REDPOTATO40 ปีที่แล้ว

    Hi! This is amazing, but I had a question.. can you maybe make a video explaining how to make an event countdown maybe for like each 15 minute multiple NPC's spawn at a certain area with weapons and you have to kill them? That'd help me so much with my game, I'm really trying to find out how to do that and It'd be amazing knowing how it's possible, Thank you ahead ♥🙏

  • @hoanghanguyen1410
    @hoanghanguyen1410 2 ปีที่แล้ว

    Thank you for your great video. I learned a lot by your ContextActionService previous clips. You earned 1 loyal subbed.

  • @littlebigbrothers110
    @littlebigbrothers110 หลายเดือนก่อน +1

    Thanks awesome Vid just one thing can i have the sword Script please?

  • @cpokhrel100
    @cpokhrel100 3 ปีที่แล้ว

    Hey! wow you've really grown u went from 300 subs to 1.29K!

    • @SimTekGameDevelopment
      @SimTekGameDevelopment  3 ปีที่แล้ว +1

      Hi Chandra! Yeah, it's growing! Still can't quit my day job though, lol.

    • @cpokhrel100
      @cpokhrel100 3 ปีที่แล้ว

      @@SimTekGameDevelopment Yea lol. I hope u grow a lot more!

  • @BlocksaverMax
    @BlocksaverMax 3 ปีที่แล้ว +6

    Great video, keep it up!
    Could you also make a video of how to make a Pathfinding Enemy NPC w/ a line of sight and if it doesn't see you it does a patrol?

    • @SimTekGameDevelopment
      @SimTekGameDevelopment  3 ปีที่แล้ว

      Thanks! Yeah, I’ve been looking into that! Pathfinding with ray casting!

    • @fakerex8388
      @fakerex8388 2 ปีที่แล้ว

      @@SimTekGameDevelopment when are you going to make that because thats what im currently looking for

  • @willum4629
    @willum4629 2 ปีที่แล้ว +1

    your voice is relaxing

  • @ahmetzngloglu6571
    @ahmetzngloglu6571 2 ปีที่แล้ว

    Thank you so much Im your new subscriber :)

  • @xtremelegogaming3065
    @xtremelegogaming3065 2 ปีที่แล้ว +11

    Hey! Thanks a lot! I had a question ...
    What if you want to have a safe place where the npc will not attack you and turns around to walk back to its set area?
    And what if you want then to randomly walk around a little bit?
    Thanks!

    • @SimTekGameDevelopment
      @SimTekGameDevelopment  2 ปีที่แล้ว +1

      Oh that's a pretty good idea!

    • @xtremelegogaming3065
      @xtremelegogaming3065 2 ปีที่แล้ว +1

      @@SimTekGameDevelopment thanks!
      can you tell me how to do it please?

    • @hardhighlightsreels
      @hardhighlightsreels 2 ปีที่แล้ว +3

      Just learn magnitude

    • @seishinstudio1249
      @seishinstudio1249 2 ปีที่แล้ว

      @@xtremelegogaming3065 theres something called magnitude that is used to measure the distance between two points. Simply subtract the position of the npc's primary part from the position of the player's character's primary part and index it with "Magnitude" [case-sensitive] to get the distance. If the distance is greater than 50 (assuming 50 is the max distance that the npc can be from the player) you can program it to move back to its area using simple movement, or pathfinding. If you dont want it to stray too far from its spawn point/area, you can use the same method/concept of magnitude to make it move back to its spawn point after it is distanced enough from it.

    • @xtremelegogaming3065
      @xtremelegogaming3065 2 ปีที่แล้ว

      @@seishinstudio1249 thanks

  • @quynhanhhoang7893
    @quynhanhhoang7893 3 ปีที่แล้ว +3

    very useful for me, thanks

  • @sirpanthergaming
    @sirpanthergaming ปีที่แล้ว +1

    sombody else posted the script not sure if it works tho
    local char = script.Parent
    local hrp = char:WaitForChild("HumanoidRootPart")
    local hum = char:WaitForChild("Humanoid")
    local sword = char:WaitForChild("ClassicSword")
    local be = char:WaitForChild("ToolBe")
    local players = game:GetService("Players")
    local function finClosestPlayersHrp(myHrp, distOfInt)
    local closestHrp = nil
    for _, ply in pairs(players:GetChildren()) do
    local plyChar = ply.Character or ply.CharacterAdded:Wait()
    local plyHrp = plyChar:WaitForChild("HumanoidRootPart")
    local tmpDis = (myHrp.Position - plyHrp.Position).Magnitude
    if tmpDis < distOfInt then
    closestHrp = plyHrp
    distOfInt = tmpDis
    end
    end
    return closestHrp
    end
    while wait(.1) do
    local closestHrp = finClosestPlayersHrp(hrp, 20)
    if closestHrp then
    hum:EquipTool (sword)
    wait(1)
    while closestHrp.Parent.Humanoid.Health > 0 do
    hum:MoveTo(closestHrp.Position, closestHrp)
    be:Fire()
    wait(.2)
    end
    hum:UnequipTools()
    else
    hum:UnequipTools()
    end
    end

  • @Qzanium
    @Qzanium 3 ปีที่แล้ว +14

    heres the script for yall:
    local rarm = script.Parent:FindFirstChild("Right Arm")
    local larm = script.Parent:FindFirstChild("Left Arm")
    function dmg(hit)
    if hit.Parent ~= nil then
    local hum = hit.Parent:findFirstChild("Humanoid")
    if hum ~= nil then
    hum.Health = hum.Health -10
    end
    end
    end
    rarm.Touched:connect(dmg)
    larm.Touched:connect(dmg)

    • @kingtigertheheavy2708
      @kingtigertheheavy2708 2 ปีที่แล้ว

      this looks nothing like the script

    • @Qzanium
      @Qzanium 2 ปีที่แล้ว

      @@kingtigertheheavy2708 it works tho

    • @martaljamoore10
      @martaljamoore10 2 ปีที่แล้ว

      @@Qzanium Liar it does not work.

    • @Qzanium
      @Qzanium 2 ปีที่แล้ว

      @@martaljamoore10 rip

  • @facefreak8170
    @facefreak8170 2 ปีที่แล้ว

    DUDE U SAVED ME THANK YOU SO MUCH

  • @macs2959
    @macs2959 2 ปีที่แล้ว

    Thanks this helped alot!

  • @beastmomki
    @beastmomki 4 หลายเดือนก่อน

    What changes do I make if the NPC is R6. The Npc cannot attack at all. (No errors appears in output.)

  • @Swan-Songs
    @Swan-Songs 2 ปีที่แล้ว +1

    Hello! Thanks a lot for the tutorial but I am having a problem, the sword will not deal damage the the player, I have no idea how to fix this could you help?

  • @jello3064
    @jello3064 2 ปีที่แล้ว +2

    are u able to do it with other melee weapons? (like the rainbow periastron for example)

    • @mrrobot4951
      @mrrobot4951 ปีที่แล้ว

      Yes with all the weapons that use event Activated

  • @jedicake3177
    @jedicake3177 3 ปีที่แล้ว +1

    thx for the information now I can make game

  • @rblxrivalsgaming
    @rblxrivalsgaming ปีที่แล้ว +1

    Could you make a enemy with a gun that shoots you?

  • @Bambuuck
    @Bambuuck ปีที่แล้ว

    I got a question regarding the animation. I did every step correctly and no errors are shown in the output, but my Dummy follows me without any animation, and just sometimes twiches its foot, but no other animation. Can you maybe help me fix this?

  • @HumanOnEarth
    @HumanOnEarth ปีที่แล้ว

    I have a musket game and this did NOT WORK! I spent so long doing this and it didn't even work because you were using a default sword...

  • @ZeroToBlack
    @ZeroToBlack 2 ปีที่แล้ว +1

    Hi how to fix the problem where the npc hits me and it completely stops

  • @arodingoya8598
    @arodingoya8598 2 ปีที่แล้ว +1

    can you explain what ply.Character or ply.CharacterAdded actully do, because i looked into the object browser but i didn't find anything like Character or CharacterAdded

    • @SimTekGameDevelopment
      @SimTekGameDevelopment  2 ปีที่แล้ว +1

      Yeah, that is unusual, so the character belongs to the player, but sometimes, like when the game is starting or you are respawning, the Character isn't ready yet (it's not attached to the player). If you do something like:
      local char = player.Character
      and the character isn't ready, char = nil. No bueno. But if you do:
      local char = player.Character or player.CharacterAdded:Wait()
      the script stops (and waits) until the CharacterAdded event is fired, which fires when the character is added. Since you waited there in the script, player.Character will have the value of the character when the script moves to the next line. So, char will have the value of the Character.

    • @arodingoya8598
      @arodingoya8598 2 ปีที่แล้ว +1

      @@SimTekGameDevelopment thank you for explaining i'll use that next time

  • @vrtoyfredboi8319
    @vrtoyfredboi8319 2 ปีที่แล้ว +2

    How do you make the NPC swing the sword with a custom animation?

    • @tepelyt
      @tepelyt 2 ปีที่แล้ว

      Change the animation id in the animation inside stringvalue called slash inside the animate script

  • @painsauchocolat5086
    @painsauchocolat5086 2 ปีที่แล้ว +1

    But if we want to use another weapon how can we put in the hand of npc

  • @granter7860
    @granter7860 ปีที่แล้ว

    Hi the npc is moving towards me but it cant hit me, how do I fix this? Ty

  • @georgeb9003
    @georgeb9003 3 ปีที่แล้ว

    mine won't move and when it dies it stays still, it says "attempt to index nil with 'WaitForChild'"

  • @sarawakgamings5960
    @sarawakgamings5960 2 ปีที่แล้ว +1

    ok so i basically went through this script for so long (i used another tool) only for me to find out i had to change the script of the tool. bruh-

  • @dl9813
    @dl9813 2 ปีที่แล้ว

    Thank you for this. This is the first thing I've created! It works great the first time but Dummy doesn't do anything after it kills me and I respawn or if I manage to get away from him. Is there something I need to add to the code?

    • @SimTekGameDevelopment
      @SimTekGameDevelopment  2 ปีที่แล้ว +1

      Oh wow, that’s one of the hardest ones. I don’t remember it well but it should keep coming after you. Run it with the output window open to see if it prints any errors to the screen. If you are outside of the distance of interest it won’t detect you. Maybe the distance of interest isn’t getting reset after it kills you. When the dummy searchers for someone and it returns nil if no one is there it should reset the dist to the default value, maybe 50 or something

    • @SimTekGameDevelopment
      @SimTekGameDevelopment  2 ปีที่แล้ว +2

      I’ll check to see if I have time tomorrow, SimTek ran out of money and I had to get a real job 😂😂

    • @dl9813
      @dl9813 2 ปีที่แล้ว

      @@SimTekGameDevelopment thanks for the quick reply! There's absolutely no rush. I just wasn't sure if I missed something. I did not run it with the output window open. I didn't know this was available but that sounds like a great tool. I'll look for it tomorrow.
      Dummy works prefect the first go around. Then when I approach him he just stands there and I let him kill me by running into his sword 😀 It seems like the loop is broken.
      I can post the code for both scripts if it helps.
      Sorry to hear about needing a real job. I'm just on a few days off and decided to check this out.
      Thanks again andi look forward to your other videos.

    • @dl9813
      @dl9813 2 ปีที่แล้ว

      @@SimTekGameDevelopment
      Ahh, I just needed some coffee and a few minutes to figure it out. I was missing the equal sign in this early line of code.
      "local be = char:WaitForChild("ToolBe")"
      It's interesting that it mostly worked even with this error in the code. Thanks again for your assistance!

  • @trollmonster3240
    @trollmonster3240 2 ปีที่แล้ว +1

    Does it only work for r15?

  • @user-kr8kx7lm3r
    @user-kr8kx7lm3r ปีที่แล้ว

    my script is working and the npc is attacking but the walk animation isnt working pls help

  • @yyyummers
    @yyyummers 2 ปีที่แล้ว

    How could i make it so he would stay still and shoot the player? And you can customise the range and dmg

  • @ketaminekween
    @ketaminekween 2 ปีที่แล้ว +3

    Can you please paste the script in desc

  • @projectskwela
    @projectskwela 5 หลายเดือนก่อน

    it does not work except the animation of holding and idle animation

  • @reflet466
    @reflet466 9 หลายเดือนก่อน

    What if I DO want the npc to be on a team with another npc?

  • @exoticz2464
    @exoticz2464 2 ปีที่แล้ว

    How do I make it so that if I have multiple they don’t accidentally kill eachother

  • @emericoceritinoplayz
    @emericoceritinoplayz 3 ปีที่แล้ว

    Uuuhh it did not work for me
    Did i do something wrong with the rig?
    (I am too young to understand why it is not working)

  • @epicodds
    @epicodds 2 ปีที่แล้ว

    Do you know anyway to make it so it stops trying to attack you once you are already far away and secondly how do you make it so it stops spamming the swing/lunge and only do it once every 2 seconds

    • @SimTekGameDevelopment
      @SimTekGameDevelopment  2 ปีที่แล้ว

      There’s a while loop where you can increase the wait time for the attacks. I don’t remember if I set a distance of interest. I’ll look at it again because I’m going to do one that runs around and punches people

  • @zooliscooler
    @zooliscooler 2 ปีที่แล้ว

    hey do you know how i could make him not deal dmg to his teammate? like i just placed 2 of them but if one starts to use sword it damages his teammate

    • @zooliscooler
      @zooliscooler 2 ปีที่แล้ว

      if they are right next to eachother

  • @ARandomKhy
    @ARandomKhy 3 ปีที่แล้ว

    i doesnt work at me i did everything that i could do it just doesnt work at the attack says "syntax error: incomplete statement: expected assignment or a functional call" and the sword script is "expected 'end' (to close 'then' line 84), got 'humanoid'

    • @SimTekGameDevelopment
      @SimTekGameDevelopment  3 ปีที่แล้ว

      You’re missing and “end”, like at the end of an if then statement.

    • @ARandomKhy
      @ARandomKhy 3 ปีที่แล้ว

      but where? ( i am a beginner idk really know how to cript) at the attack script or the sword ?

    • @ARandomKhy
      @ARandomKhy 3 ปีที่แล้ว

      @@SimTekGameDevelopment it works now but it wont move but it does dammage. The inside of my dummy look like this
      dummy

    • @justsomeonehere884
      @justsomeonehere884 2 ปีที่แล้ว

      @@ARandomKhy is it anchored

  • @Virtus647
    @Virtus647 8 หลายเดือนก่อน

    does it work with guns

  • @Kermiiiie
    @Kermiiiie 2 ปีที่แล้ว

    Hey so following this script i had a problem of the NPC not following or doing the attack animation but they hurt me if i got close enough, and i turn on debug errors and this line throws an error for me,
    for _, ply in pairs(players:GetChildren()) do
    im pretty sure its exactly how you had it but i could be wrong, feel free to call me stupid

    • @Kermiiiie
      @Kermiiiie 2 ปีที่แล้ว

      local char = script.Parent
      local hrp = char:WaitForChild("HumanoidRootPart")
      local hum = char:WaitForChild("Humanoid")
      local sword = char:WaitForChild("TempSword")
      local be = char:WaitForChild("ToolBe")
      local function finClosestPlayersHrp(myHrp, disOfInt)
      local closestHrp = nil
      for _, ply in pairs(players:GetChildren()) do
      local plyChar = ply.Character or ply.CharacterAdded:Wait()
      local plyHrp = plyChar:WaitForChild("HumanoidRootPart")
      local tmpDis = (myHrp.Position - plyHrp.Position).Magnitude
      if tmpDis < disOfInt then
      closestHrp = plyHrp
      disOfInt = tmpDis
      end
      end
      return closestHrp
      end
      while wait(.1) do
      local closestHrp = finClosestPlayersHrp(hrp, 20)
      if closestHrp then
      hum:EquipTool(sword)
      wait(1)
      while closestHrp.Parent.Humanoid.Health > 0 do
      hum:MoveTo(closestHrp.Position, closestHrp)
      be:Fire()
      wait(.2)
      end
      hum:UnequipTools()
      else
      hum:UnequipTools()
      end
      end
      This is my entire script if that would be more useful than just that line

    • @SimTekGameDevelopment
      @SimTekGameDevelopment  2 ปีที่แล้ว

      Is players spelled the same as when you defined it? What does the error say because that part looks ok

    • @desmondnoah3962
      @desmondnoah3962 2 ปีที่แล้ว

      Same

  • @umaimwuwa
    @umaimwuwa 3 ปีที่แล้ว

    Does it only work on dummys cause i use the load in characters and i did everything but mine dint walk

    • @vojin154
      @vojin154 2 ปีที่แล้ว

      can maybe help you

  • @mateoc5820
    @mateoc5820 ปีที่แล้ว

    Is there a way that I can make the enemy use special attacks that are from the weapon? Like when the player presses q, it will trigger a special attack

    • @QUBIQUBED
      @QUBIQUBED ปีที่แล้ว

      Maybe you can use Math.Random to set a range, select a number from that range to create probability, and then if that number is chosen, it will use the special attack in the weapon code.
      Since enemies can’t press Q, you’ll have to make the function play when the number is selected,
      I haven’t tested this, but this just came off the top of my head, try it out

  • @lantern515
    @lantern515 2 ปีที่แล้ว

    hey, i followed all the steps and it doesnt work for me

  • @Saikyurin
    @Saikyurin ปีที่แล้ว

    does this work for R6?

  • @Giyu_tomioka220
    @Giyu_tomioka220 3 ปีที่แล้ว +2

    Can you make it a model plz I'm lazy
    And I'll give credits to you.

    • @TheMento
      @TheMento 3 ปีที่แล้ว

      its not that hard to half your screen for a script menu and a yt video

  • @Nebula_Protogen752
    @Nebula_Protogen752 ปีที่แล้ว

    Where can I find the Rig Builder plugin?

  • @robloxflopsyyt7068
    @robloxflopsyyt7068 2 ปีที่แล้ว

    Please help; mine moves around with the sword chasing me but not actually dealing damage

    • @SimTekGameDevelopment
      @SimTekGameDevelopment  2 ปีที่แล้ว

      Do you have any errors in the output window?

    • @robloxflopsyyt7068
      @robloxflopsyyt7068 2 ปีที่แล้ว

      @@SimTekGameDevelopment Uh yes, line 19 was always the error. I can't remember if it was on the sword code or your code. Like line 19 was always the error no matter what line 19 was; even just an empty line was still an error.

  • @Palomomento
    @Palomomento 3 ปีที่แล้ว

    but i cant remove all player thing from sling shot anyone help please

  • @christophermonaghan1865
    @christophermonaghan1865 2 ปีที่แล้ว

    My neck is just standing there but I did un anchor him and he does no damage

  • @facefreak8170
    @facefreak8170 2 ปีที่แล้ว

    Wait it didnt work at the end i thought it did.. he just stood there.. wielding the sword..

  • @UniqueMcTut
    @UniqueMcTut 2 ปีที่แล้ว

    Hi nice tutorial. Can you help me pls. I want to make baller npc who throw ball to you and damage. Did u know how to make this?

  • @WiiiiiiiiiLS
    @WiiiiiiiiiLS 2 ปีที่แล้ว +1

    why mine is not moving but the animation works😭😭

    • @TopHatEgg
      @TopHatEgg 10 หลายเดือนก่อน

      Check if anchored

  • @endangeredstickman7464
    @endangeredstickman7464 2 ปีที่แล้ว

    I keep getting "attempt to index nil with Position" error

  • @Aa-YmDS_h4t6yW_0BPn4zbyYp.a5_E
    @Aa-YmDS_h4t6yW_0BPn4zbyYp.a5_E 2 ปีที่แล้ว +1

    Can you make a tutorial to make npc that shooting at player with a gun?

    • @SimTekGameDevelopment
      @SimTekGameDevelopment  2 ปีที่แล้ว

      This one does some shooting, will this work? th-cam.com/video/1Tai9cx98Ps/w-d-xo.html

  • @Yorkym_blox
    @Yorkym_blox 3 ปีที่แล้ว

    Does it work with gun ?

  • @Spiffybub
    @Spiffybub 2 ปีที่แล้ว

    can you please paste the script in the description or comments i spent a hour or 2 copying it and it dont work

  • @ramonchen5649
    @ramonchen5649 3 ปีที่แล้ว

    anyone help the output said attepemt to index nil with waitforchild

  • @Matchopoulos
    @Matchopoulos 3 ปีที่แล้ว +2

    hello. can you make a tutorial to lock a server when the match starts in your battle royale place🙏🙏🙏🙏

  • @PC_CONSTANCIA
    @PC_CONSTANCIA 2 ปีที่แล้ว

    hello friend will you have one that attacks but with weapons that shoot me?

  • @Mert-jv1je
    @Mert-jv1je 2 ปีที่แล้ว

    I have an error for some reason the dummy does not move

  • @emericoceritinoplayz
    @emericoceritinoplayz 3 ปีที่แล้ว

    i like tutorials for roblox studio

  • @MohammadDimaporo
    @MohammadDimaporo ปีที่แล้ว

    Mine dosent work...
    script:
    local char = script.Parent
    local hrp = char:WaitForChild("HumanoidRootPart")
    local hum = char:WaitForCHild("Humanoid")
    local sword = char:WaitForChild("ClassicSword")
    local be = char:WaitForChild("ToolBe")
    local players = game:GetService("Players")
    local function finClosestPlayersHrp(myHrp, distofInt)
    local closestHrp = nil
    for _, ply in pairs(players:GetChildren()) do
    local plyChar = ply.Character or ply.ChildAdded:Wait()
    local plyHrp = plyChar:WaitForChild("HumanoidRootPart")
    local tmpDis = (myHrp.Position - plyHrp.Position).Magnitude
    if tmpDis < distofInt then
    closestHrp = plyHrp
    distofInt = tmpDis
    end
    end
    return closestHrp
    end
    while wait(.1) do
    local closestHrp = finClosestPlayersHrp(hrp, 20)
    if closestHrp then
    hum:EquipTool (sword)
    wait(1)
    while closestHrp.Parent.Humanoid.Health > 0 do
    hum:MoveTo(closestHrp.Position, closestHrp)
    be:Fire()
    wait(.2)
    end
    hum:UnequipTools()
    else
    hum:UnequipTools()
    end
    end
    Sword Script:
    --Rescripted by Luckymaxer
    --EUROCOW WAS HERE BECAUSE I MADE THE PARTICLES AND THEREFORE THIS ENTIRE SWORD PRETTY AND LOOK PRETTY WORDS AND I'D LIKE TO DEDICATE THIS TO MY FRIENDS AND HI LUCKYMAXER PLS FIX SFOTH SWORDS TY LOVE Y'ALl
    --Updated for R15 avatars by StarWars
    --Re-updated by TakeoHonorable
    Tool = script.Parent
    Handle = Tool:WaitForChild("Handle")
    local be = Tool.Parent.ToolBe
    function Create(ty)
    return function(data)
    local obj = Instance.new(ty)
    for k, v in pairs(data) do
    if type(k) == 'number' then
    v.Parent = obj
    else
    obj[k] = v
    end
    end
    return obj
    end
    end
    local BaseUrl = "rbxassetid://"
    Debris = game:GetService("Debris")
    RunService = game:GetService("RunService")
    DamageValues = {
    BaseDamage = 5,
    SlashDamage = 10,
    LungeDamage = 30
    }
    --For R15 avatars
    Animations = {
    R15Slash = 522635514,
    R15Lunge = 522638767
    }
    Damage = DamageValues.BaseDamage
    Grips = {
    Up = CFrame.new(0, 0, -1.70000005, 0, 0, 1, 1, 0, 0, 0, 1, 0),
    Out = CFrame.new(0, 0, -1.70000005, 0, 1, 0, 1, -0, 0, 0, 0, -1)
    }
    Sounds = {
    Slash = Handle:WaitForChild("SwordSlash"),
    Lunge = Handle:WaitForChild("SwordLunge"),
    Unsheath = Handle:WaitForChild("Unsheath")
    }
    ToolEquipped = false
    --For Omega Rainbow Katana thumbnail to display a lot of particles.
    for i, v in pairs(Handle:GetChildren()) do
    if v:IsA("ParticleEmitter") then
    v.Rate = 20
    end
    end
    Tool.Grip = Grips.Up
    Tool.Enabled = true
    function Blow(Hit)
    if not Hit or not Hit.Parent or not CheckIfAlive() or not ToolEquipped then
    return
    end
    local RightArm = Character:FindFirstChild("Right Arm") or Character:FindFirstChild("RightHand")
    if not RightArm then
    return
    end
    local RightGrip = RightArm:FindFirstChild("RightGrip")
    if not RightGrip or (RightGrip.Part0 ~= Handle and RightGrip.Part1 ~= Handle) then
    return
    end
    local character = Hit.Parent
    if character == Character then
    return
    end
    local humanoid = character:FindFirstChildOfClass("Humanoid")
    if not humanoid or humanoid.Health == 0 then
    return
    end
    humanoid:TakeDamage(Damage)
    end
    function Attack()
    Damage = DamageValues.SlashDamage
    Sounds.Slash:Play()
    if Humanoid then
    if Humanoid.RigType == Enum.HumanoidRigType.R6 then
    local Anim = Instance.new("StringValue")
    Anim.Name = "toolanim"
    Anim.Value = "Slash"
    Anim.Parent = Tool
    elseif Humanoid.RigType == Enum.HumanoidRigType.R15 then
    local Anim = Tool:FindFirstChild("R15Slash")
    if Anim then
    local Track = Humanoid:LoadAnimation(Anim)
    Track:Play(0)
    end
    end
    end
    end
    function Lunge()
    Damage = DamageValues.LungeDamage
    Sounds.Lunge:Play()
    if Humanoid then
    if Humanoid.RigType == Enum.HumanoidRigType.R6 then
    local Anim = Instance.new("StringValue")
    Anim.Name = "toolanim"
    Anim.Value = "Lunge"
    Anim.Parent = Tool
    elseif Humanoid.RigType == Enum.HumanoidRigType.R15 then
    local Anim = Tool:FindFirstChild("R15Lunge")
    if Anim then
    local Track = Humanoid:LoadAnimation(Anim)
    Track:Play(0)
    end
    end
    end
    --[[
    if CheckIfAlive() then
    local Force = Instance.new("BodyVelocity")
    Force.velocity = Vector3.new(0, 10, 0)
    Force.maxForce = Vector3.new(0, 4000, 0)
    Debris:AddItem(Force, 0.4)
    Force.Parent = Torso
    end
    ]]
    wait(0.2)
    Tool.Grip = Grips.Out
    wait(0.6)
    Tool.Grip = Grips.Up
    Damage = DamageValues.SlashDamage
    end
    Tool.Enabled = true
    LastAttack = 0
    function Activated()
    if not Tool.Enabled or not ToolEquipped or not CheckIfAlive() then
    return
    end
    Tool.Enabled = false
    local Tick = RunService.Stepped:wait()
    if (Tick - LastAttack < 0.2) then
    Lunge()
    else
    Attack()
    end
    LastAttack = Tick
    --wait(0.5)
    Damage = DamageValues.BaseDamage
    local SlashAnim = (Tool:FindFirstChild("R15Slash") or Create("Animation"){
    Name = "R15Slash",
    AnimationId = BaseUrl .. Animations.R15Slash,
    Parent = Tool
    })
    local LungeAnim = (Tool:FindFirstChild("R15Lunge") or Create("Animation"){
    Name = "R15Lunge",
    AnimationId = BaseUrl .. Animations.R15Lunge,
    Parent = Tool
    })
    Tool.Enabled = true
    end
    function CheckIfAlive()
    return (((Character and Character.Parent and Humanoid and Humanoid.Parent and Humanoid.Health > 0 and Torso and Torso.Parent) and true) or false)
    end
    function Equipped()
    Character = Tool.Parent
    Humanoid = Character:FindFirstChildOfClass("Humanoid")
    Torso = Character:FindFirstChild("Torso") or Character:FindFirstChild("HumanoidRootPart")
    if not CheckIfAlive() then
    return
    end
    ToolEquipped = true
    Sounds.Unsheath:Play()
    end
    function Unequipped()
    Tool.Grip = Grips.Up
    ToolEquipped = false
    end
    Tool.Activated:Connect(Activated)
    Tool.Equipped:Connect(Equipped)
    Tool.Unequipped:Connect(Unequipped)
    Connection = Handle.Touched:Connect(Blow)
    be.Event:Connect(Activated)

  • @sirpanthergaming
    @sirpanthergaming ปีที่แล้ว

    hey can you just paste the whole script in the comment pls 🙏ik I wont learn that way but I really dont care about learning I just wanna have a fun game lol

  • @MechanicNull
    @MechanicNull ปีที่แล้ว

    Need a little help. every time i spawn a dummy its missing an animate script.

    • @MechanicNull
      @MechanicNull ปีที่แล้ว

      If possible, Could you send the animate script code?

    • @SimTekGameDevelopment
      @SimTekGameDevelopment  ปีที่แล้ว

      @@MechanicNull I just get the animate script from my player character when I play the game. When you copy the script, make sure you turn the game off first before pasting it, or it will disappear.

    • @MechanicNull
      @MechanicNull ปีที่แล้ว +1

      @@SimTekGameDevelopment Oh ok thank you.
      Your the first ever youtuber to reply to my comment on their own video.
      Thanks Alot.

  • @skygamez0626
    @skygamez0626 2 ปีที่แล้ว +1

    Mine does damage but wont move :/

    • @SimTekGameDevelopment
      @SimTekGameDevelopment  2 ปีที่แล้ว

      Double check if the humanoidRootPart is still anchored. That gets me all the time

    • @skygamez0626
      @skygamez0626 2 ปีที่แล้ว

      @@SimTekGameDevelopmentI FIXED IT!!! but the sword wont swing :/

    • @skygamez0626
      @skygamez0626 2 ปีที่แล้ว

      wait its not moving anymore

    • @skygamez0626
      @skygamez0626 2 ปีที่แล้ว

      this is crazy

  • @leothunders9366
    @leothunders9366 3 ปีที่แล้ว

    could have just put the script in the description its not that hard if u typed it all out

  • @alphapham2060
    @alphapham2060 3 ปีที่แล้ว

    not all heroes wear cape.

    • @SimTekGameDevelopment
      @SimTekGameDevelopment  3 ปีที่แล้ว

      I love that comment!

    • @alphapham2060
      @alphapham2060 3 ปีที่แล้ว

      @@SimTekGameDevelopment Can you make script to assign NPC to a specific team?

  • @justsomeonehere884
    @justsomeonehere884 2 ปีที่แล้ว

    Mine isn't anchored, it does damage but it won't move

    • @epicodds
      @epicodds 2 ปีที่แล้ว

      did you unanchor the humanoid root part

  • @fellowhuman2560
    @fellowhuman2560 2 ปีที่แล้ว

    Hours npc coding be like:

  • @mathiaswallin5550
    @mathiaswallin5550 2 ปีที่แล้ว

    Impossible to keep up whit it and there was some fails that I can't fixs

  • @greysonbigboivue7415
    @greysonbigboivue7415 ปีที่แล้ว

    It does not work he not move and not shoot it took me so long and now I’m sad pls help

    • @greysonbigboivue7415
      @greysonbigboivue7415 ปีที่แล้ว

      Bro I’m sad because I deleted the npc with the script and now I have to do it again but it’s no point because it does not work

    • @greysonbigboivue7415
      @greysonbigboivue7415 ปีที่แล้ว

      I feel very sad sad

    • @greysonbigboivue7415
      @greysonbigboivue7415 ปีที่แล้ว

      Of you make another video to help that make me happy

  • @thenormalgamer5593
    @thenormalgamer5593 3 ปีที่แล้ว

    does this work for r6?
    edit: it doesnt work on r6 i tried it

  • @zozo7894
    @zozo7894 2 ปีที่แล้ว +1

    Awesome video SimTek, I have done all the steps corrrect and the NPC works on one of my creations on studio, but what's really odd is that when I copy the NPC and add it to my game I get this error "Character is not a valid member of LocalScript "Players.LocalScript". It's really hard to solve and I would appreciate some help, thanks for reading!

    • @SimTekGameDevelopment
      @SimTekGameDevelopment  2 ปีที่แล้ว

      I don’t think I use any local scripts in that video. You might have a rouge local script. You could search on “LocalScript” in the explorer window and rename any script that says LocalScript to something unique, that way the error will give you the name of the script where the error is happening. Gets you closer to the problem

    • @zozo7894
      @zozo7894 2 ปีที่แล้ว

      @@SimTekGameDevelopment thank you for the answer, I'll try it out

    • @zozo7894
      @zozo7894 2 ปีที่แล้ว

      @@SimTekGameDevelopment Thanks again for the help and the answer, i tried it and it worked. It have been very often I've contacted roblox devs and asked for help but have just got ignored. I really really appreciate it and you earned a new subscriber!

  • @d00m1nus
    @d00m1nus 2 ปีที่แล้ว

    what do you do if your rig is r6

  • @dominoes64
    @dominoes64 3 ปีที่แล้ว

    can you make a spectating area

  • @pika3207
    @pika3207 2 ปีที่แล้ว

    i did all your steps but the npc isnt moving

  • @kingtigertheheavy2708
    @kingtigertheheavy2708 2 ปีที่แล้ว

    my npc doesn't even move around. a little help please?

  • @eekplayz830
    @eekplayz830 3 ปีที่แล้ว

    animations not working

  • @pep152
    @pep152 2 ปีที่แล้ว

    why wont my dummy hold the tool

  • @umaimwuwa
    @umaimwuwa 3 ปีที่แล้ว

    what did i did wrong

  • @wolf9903
    @wolf9903 3 ปีที่แล้ว

    it wont work he wont even move ):

  • @ChickenPlayz12
    @ChickenPlayz12 3 ปีที่แล้ว +2

    i have been doing this for 1 hour i hope it works!

  • @granter7860
    @granter7860 ปีที่แล้ว

    12:25 10:31

  • @mariopapa5795
    @mariopapa5795 2 ปีที่แล้ว

    Hey how do i make the npc follow me please tell me this what i do no one respond execpt for me im new idk what do i do i said 3 comments in my comment

    • @mariopapa5795
      @mariopapa5795 2 ปีที่แล้ว

      Please tell me

    • @mariopapa5795
      @mariopapa5795 2 ปีที่แล้ว

      Im new

    • @mariopapa5795
      @mariopapa5795 2 ปีที่แล้ว

      Idk what to do

    • @SimTekGameDevelopment
      @SimTekGameDevelopment  2 ปีที่แล้ว

      It’s the same as the chase, you just increase the distance to the player and don’t do the attack

  • @abbyhaam8502
    @abbyhaam8502 2 ปีที่แล้ว

    WHATS THE SCRIPT?

  • @AkiroYoruko
    @AkiroYoruko 3 ปีที่แล้ว +1

    It works but it doesn't move, Please Help!

    • @uwuanims
      @uwuanims 3 ปีที่แล้ว

      is it anchored?

    • @AkiroYoruko
      @AkiroYoruko 3 ปีที่แล้ว

      @@uwuanims uhm yes?

    • @uwuanims
      @uwuanims 3 ปีที่แล้ว

      @@AkiroYoruko it has to be unanchored to move

  • @yessiryja7664
    @yessiryja7664 2 ปีที่แล้ว

    yo can somebody paste the script?

  • @crnagelives3363
    @crnagelives3363 2 ปีที่แล้ว

    can someone paste code?

  • @RozzaTD
    @RozzaTD 2 ปีที่แล้ว

    it doesnt work

    • @SimTekGameDevelopment
      @SimTekGameDevelopment  2 ปีที่แล้ว

      That’s a hard one but it does work. What errors are you getting in the output window?

    • @RozzaTD
      @RozzaTD 2 ปีที่แล้ว

      @@SimTekGameDevelopment Sorry SimTek, i already deleted it :c no need now, but thanks for replying to help!

    • @RozzaTD
      @RozzaTD 2 ปีที่แล้ว

      @@SimTekGameDevelopment Also, when i played the animations worked, but it stayed still and didnt attack.

    • @WiiiiiiiiiLS
      @WiiiiiiiiiLS 2 ปีที่แล้ว

      same to me it stayed just in one space but I didnt deleted it I'm still finding A way how to make the npc walks