Artyom888 Posted January 2, 2020 Share Posted January 2, 2020 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
Motar2k Posted January 2, 2020 Share Posted January 2, 2020 @Artyom888 for i, player in ipairs(getElementsByType("player")) do --player - localPlayer if player ~= localPlayer then table.insert(playersList, player) end end Link to comment
Artyom888 Posted January 2, 2020 Author Share Posted January 2, 2020 (edited) 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 January 2, 2020 by Artyom888 Link to comment
Motar2k Posted January 2, 2020 Share Posted January 2, 2020 28 minutes ago, Artyom888 said: @Avival Thanks It works! Please tell me how it works? ~= means different from if is a condition if player ~= localPlayer then means If the player is different from localPlayer If you need help, don't hesitate to send me a message 1 Link to comment
Scripting Moderators ds1-e Posted January 2, 2020 Scripting Moderators Share Posted January 2, 2020 (edited) 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 January 2, 2020 by majqq 1 Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now