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:

plrs = game:GetService("Players")
plrs.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:

plrs = game.Players:GetPlayers()

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

for _, player in pairs(plrs) do

end

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:

local plrs = game.Players:GetPlayers()

for _, player in pairs(plrs) do
    if player.Character and player.Character:Fi ndFirstChild("Humanoid") then
        player.Character.Humanoid.Health = 0
    end
end

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:

Players = game.Players:GetChildren() --Gets a table of all the players

for i=1,#Players do --Sets a loop to go through all the players
    if Players[i].Character then --Finds if their character is existant
        Player.Character.Humanoid.Health = 0 --Sets health to 0 (Kills)
    end
end

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

--Honestly, all you need to do is this:

for i, v in pairs(game.Players:GetChildren())

-- creates a table of all the children of "Players"
do if v:IsA("Player")
-- i and v are both variables. Since the table is created like this:
--1 | Random Player
--2 | Random Player2
--3 | Random Player3

--i | v

--i is the number on the left side
--v is the object / player on the right side 
--Both of these variables can change to whatever you want them to be.
--Now you choose what v's you want to do the command to. You want to make sure that you're -------indexing a player, which is why it says v:IsA("Player"). If it wasn't a player it would "scrap" the -------ones that aren't and not use them for the rest of the code. Since in this case you want to do it to ----all of them, you'd do this

then v.Character.Torso:remove()
end
end

--Here is the whole script

for i, v in pairs(game.Players:GetChildren()) do if v:IsA("Player") then
v.Character.Torso:remove()
end
end

--Keep in mind, you need 2 ends. One to close the for, and one to close the if.




Answer this question