Purpose: Get all players in the game, and Kill them >:D. Broken Code:
1 | plrs = game:GetService( "Players" ) |
2 | plrs.Character.Humanoid.Health = 0 |
I Know its Wrong and Possibly WAY off, so all help is appreciated and thanks for reading :D
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:
1 | plrs = game.Players:GetPlayers() |
Now we want to go through the players and kill each one
1 | for _, player in pairs (plrs) do |
2 |
3 | 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:
1 | local plrs = game.Players:GetPlayers() |
2 |
3 | for _, player in pairs (plrs) do |
4 | if player.Character and player.Character:Fi ndFirstChild( "Humanoid" ) then |
5 | player.Character.Humanoid.Health = 0 |
6 | end |
7 | end |
That's all! you had the basic idea of it. Hope this helped!
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:
1 | Players = game.Players:GetChildren() --Gets a table of all the players |
2 |
3 | for 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 |
7 | 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
plrs = game:GetService("Players") plrs.Character.Humanoid.Health = 0
01 | --Honestly, all you need to do is this: |
02 |
03 | for i, v in pairs (game.Players:GetChildren()) |
04 |
05 | -- creates a table of all the children of "Players" |
06 | do 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 |