Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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

3 comments

0

It doesnt work in this case, thank you anyways.

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.

0

I used "GetChildren()" and it worked perfectly.

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

This discussion is preserved as it was. New answers, comments, and votes are closed.