Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago
Edited 6 years ago

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

Log in to vote
0
Answered by 6 years ago

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.

0
Yeah! Thanks so much it works now :^) NikkoTheJesusMan 3 — 6y
0
You can just use Part:GetTouchingParts() User#19524 175 — 6y
Ad

Answer this question