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

How to select ALL other players in game?

Asked by 5 years ago

Ok. So I want to select all players that aren't me. I will use this to make them stop moving, and I was thinking about making a table. Like

local plrs = ...

local MasterControl = require(plrs:WaitForChild("PlayerScripts"):WaitForChild("ControlScript"):WaitForChild("MasterControl"))

MasterControl:Disable()
MasterControl:Enable() 

So. 1st Question) Would this work? 2nd Question) How to I select ALL other players in-game?

Thank you for your help.

0
Wouldn't it be easier to just do GetPlayers() and set WalkSpeed and JumpPower to 0 if they aren't you? Vulkarin 581 — 5y

1 answer

Log in to vote
1
Answered by
Pojoto 329 Moderation Voter
5 years ago

To select all players in a game, you can use a for loop.

for i, loopPlayer in pairs(game.Players:GetPlayers()) do
    --Disable master control here using "loopPlayer" as player--
end

Basically, the for loop will get a list of all the current players in the game with game.Players:GetPlayers() and then it will loop through each player found.

Every loop it will assign the variable loopPlayer to the player it has looped through. Then it will do the code to the player, then it will move on to the next player in the game, and do the same code to that player.

For example, if I wanted to kill every player in the game, I could do this:

for i, loopPlayer in pairs(game.Players:GetPlayers()) do
    loopPlayer.Humanoid.Health = 0
end

This would loop through every player, then make that player's health 0.

Keep in mind, i is the number amount of times the loop has run, and you can name that to anything. loopPlayer is also just a variable and you can name that to anything.

0
I posted a new post. Your code isn't working properly, might you help me? Fixer1987 95 — 5y
Ad

Answer this question