Jump to content

getElementsByType


Artyom888

Recommended Posts

 

Please tell me how to remove localPlayer from the resulting table and leave only players on the server?

 

I get a list of all players including localPlayer I would like localPlayer not to be selected in the list.

   for i, player in ipairs(getElementsByType("player")) do
            --player - localPlayer 
            table.insert(playersList, player)
    end

 

Link to comment
29 minutes ago, Avival said:

@Artyom888


for i, player in ipairs(getElementsByType("player")) do
--player - localPlayer 
	if player ~= localPlayer then
		table.insert(playersList, player)
	end
end

 

@Avival
Thanks It works!
Please tell me how it works?
Edited by Artyom888
Link to comment
  • Scripting Moderators
51 minutes ago, Artyom888 said:

@Avival
Thanks It works!
Please tell me how it works?

This will work faster and better:

local players = getElementsByType("player")
local playersList = {}
local player = nil

for i = 1, #players do
	player = players[i]

	if player ~= localPlayer then
		playersList[#playersList + 1] = player
	end
end

We use integer loop, which is fastest loop so far.

We avoid using table.insert, manually adding is faster.

Edited by majqq
  • Like 1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...