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

How can I get all players excluding the local player? [Solved]

Asked by
C1RAXY 81
5 years ago
Edited 5 years ago

Hello guys,so my problem is when I use the function GetPlayers() you basically get all players in the server, for example:

--...

local list = game:GetService('Players'):GetPlayers()

for i,v in pairs(list) do
        repeat
        wait(0.5)
        LocalPlayer.CFrame = v.Character.HumanoidRootPart.CFrame * CFrame.new(0, 0, 1) until v.Character.Humanoid.Health <= 0 
    end
end

My objetive is doesn't get the LocalPlayer, just other players. (Bc "local player" is you for example and you are a member of players)

Any idea?

Thanks.

2 answers

Log in to vote
2
Answered by 5 years ago
Edited 5 years ago

Just add a basic if statement.

local list = game:GetService('Players'):GetPlayers()

for i, v in pairs(list) do
    if not v == game.Players.LocalPlayer then
        -- run your code here
    end
end

0
It doesnt work in this case, thank you anyways. C1RAXY 81 — 5y
0
You cannot do this in a server script as how will the server script know which client to ignore? You must do this in a local script and then possibly fire to the server and then ignore the player who fired to the server. YabaDabaD0O 505 — 5y
0
I used "GetChildren()" and it worked perfectly. C1RAXY 81 — 5y
Ad
Log in to vote
0
Answered by
C1RAXY 81
5 years ago

Well I found the mistake by my self, I just used "GetChildren" Instead of "GetPlayers".

Answer this question