Categories > Coding > Lua >

How would I get all the players characters?

trollhackerdude

LUA and C# programmer

Posts: 119

Threads: 33

Joined: Jun, 2018

Reputation: 1

Posted

local plrs = game.Players:GetChildren() doesn't work.

ik im stupid :)

  • 0

I know LUA and some C#

 

and i own synapse x noob

Owen

Nickelz

vip

Posts: 6

Threads: 2

Joined: Mar, 2018

Reputation: 0

Replied

well, it's a kind of vague question, but you can do a for loop.

 

    for _,player in pairs (game:GetService("Players"):GetPlayers()) do
        if player.Character then
            player.Character.Humanoid.Health = 0

        end

    end

- this kills everybody :)

  • 0

WRD

Owner

admin

Posts: 983

Threads: 33

Joined: Dec, 2016

Reputation: 104

Replied

allPlayers = game.Players:GetPlayers()

for i,v in (allPlayers) do

--v is the player instance

print(v.Name) --Prints each player's name

end

 

I wouldn't recommend using GetChildren() because it will get every instance. GetPlayers() will only get players

  • 0

https://wearedevs.net/images/icons/youtube.png Coding Tutorials  https://i.imgur.com/z8bRyw3.png Blog

PoopMaster

SoundInfinity

noticed

Posts: 120

Threads: 23

Joined: Jul, 2019

Reputation: 9

Replied

Another way is this


local function GetCharacters(exe)

--# Makes table to insert the characters into it.

local Characters = { };

 

--# Goes through the players and add their characters to the table.

for _, Player in next, game:GetService'Players':GetPlayers() do

if exe then pcall(exe, Player.Character);end;

Characters[#Characters + 1] = Player.Character;

end;

 

return Characters;

end;

 

--# Kills all

GetCharacters(function(char)

char:BreakJoints'';

end)

  • 0

Proud creator of: WRD+

Users viewing this thread:

( Members: 0, Guests: 1, Total: 1 )