generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Remove player from tables if he/she leaves

Previous Thread :: Next Thread 
Gladii is not online. Gladii
Joined: 10 Mar 2012
Total Posts: 1713
19 Jan 2015 06:23 PM
How do I do this?

I'm having a little trouble with this.
Report Abuse
Seranok is not online. Seranok
Joined: 12 Dec 2009
Total Posts: 11083
19 Jan 2015 06:27 PM
local players = {}

game.Players.PlayerAdded:connect(function(player)
table.insert(players, player)
end)

game.Players.PlayerAdded:connect(function(player)
  for i, p in pairs(players) do
    if p == player then
      table.remove(players, i)
      break
    end
  end
end)
Report Abuse
Gladii is not online. Gladii
Joined: 10 Mar 2012
Total Posts: 1713
19 Jan 2015 06:37 PM
I'm not sure if I fully understand that script...
How is that detecting if the player left the game?
Report Abuse
Seranok is not online. Seranok
Joined: 12 Dec 2009
Total Posts: 11083
19 Jan 2015 06:38 PM
Oops, I meant to post:

game.Players.PlayerRemoving:connect(function(player)
for i, p in pairs(players) do
if p == player then
table.remove(players, i)
break
end
end
end)

So that way when the player leaves, it will remove him from the table.
Report Abuse
Dr01d3k4 is not online. Dr01d3k4
Joined: 11 Oct 2007
Total Posts: 17916
19 Jan 2015 06:38 PM
Seranok made a mistake. The second connection should be PlayerRemoving.
http://wiki.roblox.com/index.php?title=API:Class/Players/PlayerRemoving
Report Abuse
Gladii is not online. Gladii
Joined: 10 Mar 2012
Total Posts: 1713
19 Jan 2015 06:39 PM
Ohhhhh, that makes alot more sense.
Report Abuse
lordrambo is not online. lordrambo
Joined: 16 Jun 2009
Total Posts: 20628
19 Jan 2015 06:42 PM
Is there any reason not to use game.Players:GetPlayers()?
Report Abuse
Goulstem is not online. Goulstem
Joined: 04 Jul 2012
Total Posts: 7177
19 Jan 2015 06:44 PM
Seranok how do you tab your code on here? O:
Report Abuse
Seranok is not online. Seranok
Joined: 12 Dec 2009
Total Posts: 11083
19 Jan 2015 06:44 PM
If you're maintaining a list of players, then you should just call game.Players:GetPlayers() like lordrambo said. But if you are doing something fancy like:

local players = {
{ player = [Reference to player object], points = 5 }
}

Then obviously :GetPlayers() will not suffice.
Report Abuse
Seranok is not online. Seranok
Joined: 12 Dec 2009
Total Posts: 11083
19 Jan 2015 06:46 PM
Hold down `Alt` and then press 0, 1, 6, and 0 on the number pad. This will create a space character. Copy and paste this space character.
Report Abuse
chimmihc is not online. chimmihc
Joined: 01 Sep 2014
Total Posts: 17143
19 Jan 2015 06:47 PM

d
Report Abuse
Goulstem is not online. Goulstem
Joined: 04 Jul 2012
Total Posts: 7177
19 Jan 2015 06:52 PM
function test()
    print'test';
end

test''

O:::::
Report Abuse
KOTwarrior is not online. KOTwarrior
Joined: 13 Jun 2012
Total Posts: 4376
19 Jan 2015 06:54 PM
test=''function yo()
print(test);
end;


yo();
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image