Touch event affecting multiple players

I want to make a touch event effect multiple people, but i’m a very :sleeping::sleeping::sleeping::sleeping::sleeping::sleeping::sleeping::sleeping::sleeping::sleeping: and last time i remember trying it did nothing but double the damage

Way too vague, the title and sparse text you chose to describe the issue offers no information about the issue itself, or the context of the issue, or the current or intended state of the issue.

Last time you tried what? Double the damage of what? The touch event? What is the touch event trying to achieve?

1 Like

Here’s something that would allow a touched event to damage multiple players (even simultaneously). With the usage of a table, it essentially creates debounces for multiple different people.

Player A touches the part and receives damage
Player B touches the part and receives damage
Player A touches the part again in under a second and receives no damage

local affectedPlayers = {}

script.Parent.Touched:Connect(function(hit)
     -- check for a player
     if hit.Parent:FindFirstChild("Humanoid") then
          -- if a specific player is not found in a table, add them to it, then damage them
          if not table.find(affectedPlayers, hit.Parent.Name) and hit.Parent:FindFirstChild("Humanoid").Health > 0 then
               table.insert(affectedPlayers, hit.Parent.Name)

               hit.Parent.Humanoid.Health -= damageAmount

               task.wait(1)

               -- remove the player from the table so they can take damage again
               local i = table.find(affectedPlayers, hit.Parent.Name)
               table.remove(affectedPlayers, i)
          end
     end
end)
1 Like

i ment damaging multiple people, without doing wonky stuff

thank you. the comments also help with understanding it.

No problem. If this solved your issue, I recommend marking it as a solution in case someone else with the same problem as you find this post in the future.

Good luck!

Here is an script that should effect nearby people in a X number radius

local part = game.Workspace.Part

local touchInterest = Instance.new("TouchInterest", part)
touchInterest.Radius = 5

local function onTouched(otherPart)
    local humanoid = otherPart.Parent:FindFirstChildOfClass("Humanoid")
    if humanoid then
        local fire = Instance.new("Fire", humanoid.RootPart)
        fire.Size = 5
        fire.Heat = 15
        fire.Color = Color3.new(1, 0.5, 0)
        fire.SecondaryColor = Color3.new(1, 0, 0)
        wait(5)
        fire:Destroy()
    end
end

touchInterest.Touched:Connect(onTouched)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.