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

Kill All Players?

Asked by 9 years ago

Purpose: Get all players in the game, and Kill them >:D. Broken Code:

1plrs = game:GetService("Players")
2plrs.Character.Humanoid.Health = 0

I Know its Wrong and Possibly WAY off, so all help is appreciated and thanks for reading :D

3 answers

Log in to vote
11
Answered by 9 years ago

You have the start of it, and you know how to kill players. But plrs is a service not a player object.

This is how we get a table of all the players:

1plrs = game.Players:GetPlayers()

Now we want to go through the players and kill each one

1for _, player in pairs(plrs) do
2 
3end

That will run the code in the for loop as many times as there are indexes in the table plrs

Now we want to kill them:

1local plrs = game.Players:GetPlayers()
2 
3for _, player in pairs(plrs) do
4    if player.Character and player.Character:Fi ndFirstChild("Humanoid") then
5        player.Character.Humanoid.Health = 0
6    end
7end

That's all! you had the basic idea of it. Hope this helped!

0
Thank You viralmoose 65 — 9y
Ad
Log in to vote
3
Answered by
dyler3 1510 Moderation Voter
9 years ago

First of all, by getting the service "Players", you're just accessing the Parent of all the Players in the game. To get each Player, you would need a loop, that reads through a table of all the players, and sets their Humanoid Health to 0.

Here's what that would look like:

1Players = game.Players:GetChildren() --Gets a table of all the players
2 
3for i=1,#Players do --Sets a loop to go through all the players
4    if Players[i].Character then --Finds if their character is existant
5        Player.Character.Humanoid.Health = 0 --Sets health to 0 (Kills)
6    end
7end

Hopefully, this helped clear things up for you. If you have any more problems/questions, please leave a comment below. Hope I helped :P

Log in to vote
0
Answered by 9 years ago

plrs = game:GetService("Players") plrs.Character.Humanoid.Health = 0

01--Honestly, all you need to do is this:
02 
03for i, v in pairs(game.Players:GetChildren())
04 
05-- creates a table of all the children of "Players"
06do if v:IsA("Player")
07-- i and v are both variables. Since the table is created like this:
08--1 | Random Player
09--2 | Random Player2
10--3 | Random Player3
11 
12--i | v
13 
14--i is the number on the left side
15--v is the object / player on the right side
View all 30 lines...

Answer this question