Need Help With Mob Script

Hell guys, I am Ranger, this is my first ever post. My problem is that I do not know how to create a mob that you can attack you and you can attack it. The problem is that I tried to use some of the scripts from YT but i did not understand so it would really be appreciated if you provide me with a solution. I want a script that attacks you and then you can attack it back, just like the one in islands in which you can attack it and also it can attack you. It would really help me in my game.

[Edit: fixed some grammatical errors]

1 Like

You’re trying to run before you can walk. Learning the basics of scripting are essential before diving into complex coding as you will at least need a basic understanding of LUA to even be able to interpret scripts.

My recommendation would be to research the things you don’t understand in separate tutorials, instead of trying to understand it without an explanation and implement it into your game.

1 Like

Thank I will try my best to do it i just wanted the code since I did not find any good tutorials. well thank you for the recommendation. i wanna have some script as a reference. But thank you nonetheless

Thank You

1 Like

Hello, ranger_meer! Welcome to the DevForum! You might want to use a .Touched function for the attacking you script. For example.
local Damage = 20

local Damage = 20
local debouce = false

for _,v in pairs(Path_To_Model:GetChildren()) do
   v.Touched:Connect(function(hit)
  if not debounce then
     debounce = true
        hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - Damage
       wait(2)
       debounce = false
      end
   end)
end

Hopes this helps. Happy holidays!

1 Like

Okay I understand the damaging part of your script. Thank you very much. Happy Holidays to you too!

Ray tracing is way better than .Touched

1 Like

How about marking it as a Solution? Also, follow a tutorial on YouTube about “PathFindingService”, it will help you a lot with your model following you. You can also just use a free model sword, which will provide everything to damage it. As long as your model has a Humanoid, you’ll be good to go. And thank you!

so the guy has to be a humanoid in order for it to work, got it. Thank you very much.

1 Like

Correct. The Humanoid provides pretty much everything to make your model work. Also, please try using grammar on the DevForum. Thank you.

:sweat_smile: thank you for the advice. I will try to improve it as much as possible :sweat_smile:

1 Like

You’re welcome. Also, I changed the script to prevent spam from the damaging. Use that version other than the other one I provided.

alright thank you very much you have helped me a lot.

You’re welcome. I hope you continue your journey with programming. It can be a very good thing to have on your resume later on when you get a job. Stay safe, happy holidays, and happy programming!