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

How do I kill everyone inside of a specific team?

Asked by
DemGame 271 Moderation Voter
4 years ago
Edited 4 years ago

I am trying to kill everyone inside of a specific team once a button is pressed. I already dealt with connecting a remoteEvent to when a button is pressed, so I am able to put this on a normal script.

This is my code right now:

01local seconds = game.ReplicatedStorage.Seconds
02local ReplicatedStorage = game:GetService("ReplicatedStorage")
03local event = Instance.new("RemoteEvent", ReplicatedStorage)
04event.Name = "EndRound"
05local plrs = game.Players:GetChildren()
06 
07 
08 
09 
10local function EndRoundNOW()
11    for i, v in ipairs(plrs) do
12        if v.Team == "Playing" then
13            v.Humanoid:TakeDamage()
14        end
15    end
16    print("someone wants to end the round")
17    seconds.Value = 0
18end
19 
20event.OnServerEvent:Connect(EndRoundNOW)
0
do :GetChildren on the team and for i,v in pairs and kill the players from that fifayy 28 — 4y
0
Can you give an example through a block of code so that I can mark it as an answer? Thanks for the suggestion, though. DemGame 271 — 4y

2 answers

Log in to vote
4
Answered by 4 years ago
Edited 4 years ago
1for index,value in pairs(game:GetService("Players"):GetPlayers()) do
2    if value.Team == game:GetService("Teams")["Team Name"] then
3        pcall(value.Character.BreakJoints,value.Character)
4    end
5end

Here you go! This does exactly what you wish for.

0
Thanks. DemGame 271 — 4y
0
gj you beat me to it raid6n 2196 — 4y
Ad
Log in to vote
1
Answered by
zadobyte 692 Moderation Voter
4 years ago
Edited 4 years ago
1local plrs = game.Players:GetChildren()
2 
3for i, v in ipairs(plrs) do
4    if v.Team == Teams["TeamName"] then
5        v.Character.Humanoid:TakeDamage()
6    end
7end

mb made some mistakes but yeah, moon's right

0
For me it doesn't work and nothing is in the output... DemGame 271 — 4y
0
what script do you have? edit your original post zadobyte 692 — 4y

Answer this question