cheez55
|
  |
| Joined: 19 Oct 2008 |
| Total Posts: 646 |
|
|
| 09 Apr 2014 11:48 PM |
| So I just want a single-letter variable to represent a player (not in Workspace) in the server. I know there's the "for i, v in pairs(game.Players:GetPlayers()) do" method where v is the player, but I get the feeling there's a simpler way to go about it. |
|
|
| Report Abuse |
|
|
|
| 09 Apr 2014 11:55 PM |
That loops through all players. If you want that specific functionality, you have no choice but to use a loop. And a for loop is the most intuitive, especially with that pairs() function.
Are you by chance looking for a single player, rather than a list? |
|
|
| Report Abuse |
|
|
|
| 09 Apr 2014 11:57 PM |
plrs = game.Players:GetPlayers() repeat wait() plrs = game.Players:GetPlayers() until #plrs>0 FirstPerson = plrs[1] print (FirstPerson.Name)
|
|
|
| Report Abuse |
|
|
| |
|
powertool
|
  |
| Joined: 01 Feb 2008 |
| Total Posts: 3771 |
|
|
| 10 Apr 2014 12:29 AM |
| for _,v in pairs(game.Players:GetPlayers()) do(stuff) end |
|
|
| Report Abuse |
|
|
powertool
|
  |
| Joined: 01 Feb 2008 |
| Total Posts: 3771 |
|
|
| 10 Apr 2014 12:30 AM |
That's the easiest way to go about it, because we're not using the variable index.
--Shira the resident Днище |
|
|
| Report Abuse |
|
|
cheez55
|
  |
| Joined: 19 Oct 2008 |
| Total Posts: 646 |
|
|
| 10 Apr 2014 12:32 AM |
Okay so I guess the pairs method is the best. So what if I wanted to change the text in everyone's PlayerGui twice in 3 seconds like this:
for i, b in pairs(game.Players:GetPlayers()) do b.PlayerGui.ScreenGui.TextBox.Text="Text1" wait(3) b.PlayerGui.ScreenGui.TextBox.Text="Text2" end
This code breaks easily and the only solution I can find is to do the "for" loop AGAIN after the wait time and end the first loop before the wait time. That's the main reason why I need to know :P |
|
|
| Report Abuse |
|
|
|
| 10 Apr 2014 12:35 AM |
for i, b in pairs(game.Players:GetPlayers()) do ypcall(function() b.PlayerGui.ScreenGui.TextBox.Text="Text1" end) end wait(3) for i, b in pairs(game.Players:GetPlayers()) do ypcall(function() b.PlayerGui.ScreenGui.TextBox.Text="Text2" end) end |
|
|
| Report Abuse |
|
|