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

Why my damage script only damages a single person when several players touch it?

I am using a debounce for this, I don't want the part spam :TakeDamage(10) making it unfair, it is also unfair because a single unlucky person will get hit. I want to make the part damage several players without making the part spam alots of :TakeDamage() making the part overpowered. Here's an example:

local debounce = false
script.Parent.Touched:Connect(function(hit)
	local human = hit.Parent:FindFirstChildOfClass("Humanoid")
	if hit.Parent.Name ~= "cherrythetree" then
		if human and debounce == false then
			debounce = true
			human:TakeDamage(10)
			wait(2)
			debounce = false
		end
	end
end)

Anyone help???

7 comments

0

ur debounce is wrong

0

ur script is basically saying once one player touches it, it will wait 2 seconds before accepting the input of another player touching it

0

So what will I use? else or wait(2) or disable debounce?

0

have the debounce on the client side or have a plr debounce list

0

ur method works fine when there is only one guy touching the thing

0

however when a lot of people touch it at once the logic will tell u it cant simultaneously damage them all

0

Use coroutines.

1 answer

✓ Accepted answer

You could make the debounce per-player instead of just having one variable.

local debounce_container = {}

script.Parent.Touched:Connect(function(hit)
	local human = hit.Parent:FindFirstChildOfClass("Humanoid")
	local name  = hit.Parent.Name
	if name ~= "cherrythetree" then
		if human and debounce_container[name] ~= true then
			debounce_container[name] = true
			human:TakeDamage(10)
			wait(2)
			debounce_container[name] = false
		end
	end
end)

1 comment

0

Thanks! I forgot to rename the two villagers with the same name so the script won't be confused. So I accidently unaccepted for thinking it did not work.

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