How do I make characters attack consistently?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I am making a game with npcs that have a hitbox with a set damage and rate.

  2. What is the issue? Include screenshots / videos if possible!
    The issue is that since i’m using the touched event, they only manage to land 2 or 3 hits, 5 max, and also, there is a delay when a few more npcs than usual are in the game, so sometimes the enemies will just group up in one spot and wait 10 seconds for everyone to attack at the same time.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve been thinking of recycling my turret system, because it attacks consistently and was also used as a replacement because I was going to make a tower defense game with touched events, but I don’t know if it’ll be the right thing, or if it will fit correctly.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
Here’s a script from one of the ally hitboxes.

local debounce = false
local dances = {script.Animation1,script.Animation2}
local Humanoid = script.Parent.Parent:WaitForChild('NPC')
local stabs = {script.Parent.Hit,script.Parent.Hit2,script.Parent.Hit3}

function onTouched(hit)
        local human = hit.Parent:findFirstChild("Enemy")
	if (human ~= nil) and human.Health>0 then
		if not debounce then
			debounce = true
			local dance = Humanoid:LoadAnimation(dances[math.random(#dances)])
			dance:Play()
			Humanoid.WalkSpeed = 0
			wait(0.5)
			human.Health = human.Health - 10
			stabs[math.random(#stabs)]:Play()
			Humanoid.WalkSpeed = 16
			wait(0.5)
			debounce = false
        end
	end
	end
script.Parent.Touched:connect(onTouched)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

I highly recommend using the ZonePlus module as opposed to the Touched event (which is quite buggy), as it uses the SpatialQuery API (much more reliable).
You could convert all the body parts into Zones themselves and check for a weapon or projectile entry into the zone, or you could create new parts around the body parts so that you can grant leeway for near misses and the like.

yes, the hitboxes are separate parts from the entire r15 model, they are just welded to the humanoidrootpart

Use raycasthitbox for hitboxes. Not a module meant for Zones.

1 Like

i think you got it wrong. im saying that they dont land more than 2 hits, not that it never even hits in the first place, im talking about how it stops registering when a character is too close, not that it never registers a single hit. i think i will just reuse the turret system

ok it worked perfectly with the turret system sorry for bothering

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.