Categories > Coding > Lua >
How would I get all the players characters?
Posted
local plrs = game.Players:GetChildren() doesn't work.
ik im stupid :)
I know LUA and some C#
Â
and i own synapse x noob
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 :)
Cancel
Post
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
Cancel
Post
https://wearedevs.net/images/icons/youtube.png Coding Tutorials https://i.imgur.com/z8bRyw3.png Blog
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)
Cancel
Post
Proud creator of: WRD+
Users viewing this thread:
( Members: 0, Guests: 1, Total: 1 )
Cancel
Post