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

HOW WOULD I MAKE A SCRIPT THAT DAMAGES MULTIPLE PEOPLE AT ONCE WHILE THEY ARE TOUCHING A BRICK?

I've tried with this script and many other scripts but they only damage 1 person at a time

local trapPart = script.Parent
local Debounce = false
local function onPartTouch(otherPart)
local partParent = otherPart.Parent
local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")

if ( humanoid ) then
if Debounce == false then
Debounce = true
    humanoid:TakeDamage(5.5)
wait(0.2)
Debounce = false
end
end
end

trapPart.Touched:Connect(onPartTouch)

1 answer

✓ Accepted answer

Your debounce will only allow damage to one player at once after which the code will wait. You would use a table to keep track of what has had damage taken within your cooldown time.

Example:-

local trapPart = script.Parent
local plrServ = game:GetService("Players")
local lst = {}

trapPart.Touched:Connect(function(hit)

	local humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid")
	if not humanoid then return end -- no humanoid
	if lst[humanoid] then return end -- humanoid is in the list

	lst[humanoid] = true
	humanoid:TakeDamage(5.5)
	wait(0.2)
	lst[humanoid] = nil
end)

The table will act like a debounce as you cannot take damage if you are in the table.

I hope this helps.

2 comments

0

Yeah! Thanks so much it works now :^)

0

You can just use Part:GetTouchingParts()

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