So i am having a breakdown, i have no idea how to start with the npc script. I don't need anyone to make the script for me, i need someone who'd either tell me what i'm supposed to do in short notes, or someone who'd give me the dev wiki article link since i couldn't find anything that would help me. I would really appreciate anyone who'd help me learn this, it's quite important.
Ive actually also needed help with this but after a while of trying to get help on how to make npc's that fight back i got nothing. so i went and using my own skills created my own script and its pretty simple. To make the script for the npc to fightback you want to make a function play when the npc is touched if script.Parent.Parent.Parent.UpperTorso.Touched then
or script.Parent.Parent.Parent.UpperTorso.Touched:Connect(function(hit)
and then once this part of the script is done you then want to get a animation to play or you dont have to but i did anyway so when the function plays the npc does a animation where he swings his sword. Next you want to go ahead and make a few lines of script where the npc damages the player. what ive done is i have a npc that is holding a sword so when he swings the sword and it touches a object with a Humanoid
it damages it by writing these lines:
local char = hit.Parent --gets the object that touches the npc local human = char:FindFirstChild("Humanoid") -- getting the humanoid human.Health = human.Health - 25 -- damages the humanoid
im sure theres another way you can damage the humanoid in a more proper way but this is what ive done and its pretty simple, also this was all done in a serverscipt in the npc.
hope this helped you!
For starters, I would look into raycasting to determine how far away all the players are and if they are in the line of the sight of the NPC https://developer.roblox.com/en-us/articles/Making-a-ray-casting-laser-gun-in-Roblox. I would make a loop that refreshes every two-ish seconds to not have too much lag. There are two ways you can go at moving the NPC. The first one is a simple CFrame which can get a floating effect for an NPC(I don't suggest). The second one would be based around "Humanoid:MoveTo" https://developer.roblox.com/en-us/api-reference/function/Humanoid/MoveTo. Then add some part to your script that makes it so that the NPC plays some sort of animation and for example swings a sword(with detection you can use raycasting). Then to top it all of, make it so that the humanoid breaks joints once it's health is at 0 so that it gives a more realistic death effect. Hope this helps!