How to kill all when a part touches another part

is there a way to script this because ive been trying to script this for like an hour now and i cant script tbh so is there any way someone can help me with this

Use .Touched event, then check if the hit.Name == PartYouWant.Name, then loop through all player and set their Health to 0.

4 Likes

Adding on to what above. Ill explain more clearly:

When a part is touched, you can check what the hit was, by putting β€œhit” as a parameter inside the parenthesis in the touched function.
example:

workspace.Part.Touched:Connect(function(hit) -- hit is the parameter
-- add the for loop
end)

You can check if the part you want was hit using an if statement:

-- inside the touched function
if hit.Name == EnterYourPartNameHere then
-- loop to kill players
end

Next, to kill all players, you can do a for loop.

for i, v in ipairs(game:GetService("Players"):GetPlayers()) do 
    v.Character.Humanoid.Health = 0
end

What the for loop does it loops through the array of player names and then just does what we say the script to do.

1 Like

Ensure you have an if statement to double check that their Character exists with a Humanoid (via FindFirstChild).

1 Like