Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do i make a touch function that hits multiple people, but only once?

Im making an aura attack move, but its only able to attack 1 person at a time. Here is my script

Strong.Touched:connect(function(hit)

if not debounce then return end
debounce = false
local dmg = math.floor(script.Parent:FindFirstChild("Charging").Value / 1.55 + baseAtk + 1)
local opponent = hit.Parent:findFirstChild("Humanoid") or hit.Parent.Parent:findFirstChild("Humanoid")
		if opponent and opponent ~= player.Character.Humanoid then
		   opponent:TakeDamage(dmg)

wait(0.23)
debounce = true	
end)

1 answer

Your usage of a debounce variable is stopping it from running on more than one player at a time. Since, I assume, you have the debounce there to stop it from damaging the same player more than once, you should use a table for that instead:

local debounceTab = {};
Strong.Touched:Connect(function(hit)
	local opponent = hit.Parent:FindFirstChild("Humanoid") or hit.Parent.Parent:FindFirstChild("Humanoid");
	if opponent and opponent ~= player.Character.Humanoid then
		if debounceTab[opponent] then return end;
		debounceTab[opponent] = true;
		local dmg = math.floor(script.Parent:FindFirstChild("Charging").Value / 1.55 + baseAtk + 1)
		opponent:TakeDamage(dmg)
		wait(0.23)
		debounceTab[opponent] = nil;
	end
end)

Also, I noticed you had an end missing in your code. I'm not sure how it didn't error. Make sure you correctly indent your code!
Hope this helped.

This discussion is preserved as it was. New answers, comments, and votes are closed.