How can I make my attack damage everyone that touches it and not only one dummy?

Hello,

I’m trying to make my attack damage all the enemies that touches it and not only one, but I have no clue how to do that.


Example of what I want to achive :

image

What I have :

Any help is very appreciated! :smiley:

1 Like

Are you using a .Touched event on the ‘attack/arm thingy’?

If so you might have set a debounce for it like this:

local debounce = false

thing.Touched:Connect(function(hit)
    if (not debounce) then
        debounce = true
        print(hit)
        task.wait(1)
        debounce = false
    end
end)

Instead you could use a different type of debounce like this:

local debouncedParts = {}

thing.Touched:Connect(function(hit)
    if (not debouncedParts[hit]) then
        debounce[hit] = true
        print(hit)
        task.wait(1)
        debounce[hit] = nil
    end
end)

Something along the lines of that (Didn’t test it)

2 Likes

Use Raycasts,
Fire them Opposite to the Direction the Player is Facing.
(This will make the ray go Behind the Dummy you originally attacked)

Now Just Check if The .Instance of the Resulted Ray Has A Humanoid,
If it has a humanoid, that means we need to damage it And Continue the Ray To Go And Search for More Dummy’s.

If the .Instance of the Resulted Ray is not a humanoid, that means that there is no more dummys behind the One Original Dummy, so we just damage that one dummy and thats it.

1 Like

Yeah I did use .Touched

Tbh, I watched some tutorials but it didn’t work. The tutorial was telling me to create a table and then put everyone that touches the hitbox inside of it.

1 Like

May I see the code block that manages the .Touched event?

1 Like

I won’t really interfere, but the reason .Touched doesn’t work is because it’s broken. It has trouble firing for whatever reason. The best way I think you could handle damaging the enemies is to raycast, or possibly do something with Region3.

1 Like

Sure.

local TouchedEnemies = {}
local DamageDebounce = false

Hitbox.Touched:Connect(function(hit)
    if hit.Parent.Name == Character.Name then return end

    if hit and not DamageDebounce then
      hit.Parent:FindFirstChildWhichIsA("Humanoid") then
       DamageDebounce = true
       hit.Parent:FindFirstChildWhichIsA("Humanoid"):TakeDamage(20)
       table.insert(TouchedEnemies, hit.Parent)
       wait(2)
       DamageDebounce = false
    end
end)
1 Like

You could possibly try this:

local TouchedEnemies = {}
local DamageDebounces = {}

Hitbox.Touched:Connect(function(hit)
	if hit.Parent.Name == Character.Name then 
		return 
	end

	if not DamageDebounces[hit] then
		hit.Parent:FindFirstChildWhichIsA("Humanoid")
	
		DamageDebounces[hit] = true
	
		hit.Parent:FindFirstChildWhichIsA("Humanoid"):TakeDamage(20)
	
		table.insert(TouchedEnemies, hit.Parent)
	
		task.wait(2)
	
		DamageDebounces[hit] = nil
	end
end)

Instead of a debounce for every enemy, each enemy now has it’s own damage debounce.

2 Likes

I’m currently trying that, thx

Nvm it doesn’t work. It doesn’t even damage the enemy anymore.

local Hitbox = script.Parent.Handle
local Character = game:GetService('Players').LocalPlayer.Character or game:GetService('Players').LocalPlayer.CharacterAdded:Wait()
local DamageDebounce = false

Hitbox.Touched:Connect(function(hit)
	if hit.Parent.Name == Character.Name then return end
	if hit ~= nil and DamageDebounce == false then
		if hit.Parent:FindFirstChild('Humanoid') and hit.Parent:IsA('Model') then
			DamageDebounce = true
			hit.Parent['Humanoid']:TakeDamage(20)
			local function ray()
				local Paramas = RaycastParams.new()
				local ignore = {hit.Parent,Hitbox}
				repeat 
					Paramas.FilterDescendantsInstances = ignore
					Paramas.FilterType = Enum.RaycastFilterType.Blacklist
					Paramas.IgnoreWater = true
					
					local result = true
					local raycastResult = workspace:Raycast(hit.Position, -(hit.Parent.HumanoidRootPart.CFrame.LookVector) * 100, Paramas)
					if raycastResult then
						if raycastResult.Instance then
							if raycastResult.Instance.Parent:FindFirstChild('Humanoid') and raycastResult.Instance.Parent:IsA('Model') then
								raycastResult.Instance.Parent['Humanoid']:TakeDamage(20)
								table.insert(ignore,raycastResult.Instance.Parent)
							else
								result = false
							end
						else
							result = false
						end
					else
						result = false
					end
					wait()
				until result == false
			end
			ray()
			wait(2)
			DamageDebounce = false
		end		
	end
end)

edit the script variables on top accordingly
(change hitbox to your hitbox and character to your character or whatever)

i edited the script, copy paste again.

1 Like

Nope, tried everything and still doesn’t function correctly

can you show your script? like the one you copy pasted from me and edited the variables.
i attached a video to my previous reply, and it works for me.

1 Like