I made a combat system but I want to know how would you make it where an NPC could have the same combat system as the player?
You can do it like this:
Multiple hitboxes, which will detect when the function will strike.
To add fighting/blocking more player-like = math.random(.1,.2) < or something like that
Guns = raycasting
Moving = pathfinding
You know the drill
Sorry if you don’t understand.
Need more information because there are multiple ways to go about this. My shot in the dark answer would be to make the combat system a bunch of functions in modules which can be called upon by scripts that are linked to the player or NPC so both are using the same system.
Movement
For movement, you could find the nearest player, and then make the NPC travel towards them. To do so, you could loop through all players in the game and check for the smallest distance from the player from the NPC by using .Magnitude. Then once they’re found, you can use pathfinding to make the NPC walk towards the player.
Combat
Assuming this is a close combat system, you can again find the distance between you and the player chosen earlier in movement, and once they’re close enough start attacking them, playing the animation(s) for the fighting and manually causing the player that’s being attacked’s health to go down. To implement this, you can continually check the distance with .Magnitude, and if they’re within a certain distance, make the Player’s humanoid’s .Health go down however much you want.
Let me know if you have any questions, or if you need some help once you’re implementing you NPC combat system.
Currently, I already have an NPC that follows you, and attacks you. However, I made it where it plays one animation and I am trying to make it where after the first animation the next animation will play, however it doesn’t seem to be working since only the first animation plays.
function Hit(hit)
if hit.Parent ~= nil then
local TargetHum = hit.Parent:FindFirstChild("Humanoid")
if hit.Parent:FindFirstChild("Humanoid") ~= nil and hit.Parent:FindFirstChild("Humanoid"):IsA("Humanoid") and AttackEnabled == true and TargetHum ~= Enemy then
if not hit.Parent:FindFirstChild("NPC") then
AttackEnabled = false
delay(.5,function() AttackEnabled = true end)
if Anim and combo == 1 then
Anim:Play()
combo = 2
end
if Anim1 and combo == 2 then
Anim1:Play()
combo = 1
end
DamageTag(TargetHum.Parent,5)
end
end
end
end
I believe you may have meant to put combo
here, not number
.
Oh I fixed that after I posted this post, forgot to change it in the post as well
You can explain to me how you do to correct it because we have the same system and the same problem as you …