|
| 06 Dec 2011 02:33 PM |
I'm familar with pairs and ipairs, and I use them daily. But, somethings are hard to code with. Like if I do this:
for _,players in pairs(game.Players:GetPlayers()) do wait(3) end
This will get the players every 3 second. If I do this:
for _,players in pairs(game.Players:GetPlayers()) do m = Instance.new("Message", players.PlayerGui) m.Text = "Test" wait(8) ----WAITS 8 SECONDS m.Parent = nil end
This, won't work the way its suppose too. It usually repeats this "Test" message to every player REPEATLY to how many players are in total in the server, get my idea?
Like, lets say, there are 3 players. This message will repeat 3 times and waits 8 seconds before giving the message to another player, for every player counted in the server because, there are 3 players in total.
My question is, are there any way to get ALL the players, and by any means, only show the above contents at the SAME time, no delays, and only runs the things ONCE? Get my drift?
I might had not explained it clearly, but this is also confusing as well. It might include a lot of planning and logic (well for me, yes). |
|
|
| Report Abuse |
|
|
Spectrumw
|
  |
| Joined: 04 Aug 2009 |
| Total Posts: 13510 |
|
|
| 06 Dec 2011 02:36 PM |
for _,players in pairs(game.Players:GetPlayers()) do coroutine.resume(coroutine.create(function() m = Instance.new("Message", players.PlayerGui) m.Text = "Test" wait(8) ----WAITS 8 SECONDS m.Parent = nil end)) end
Maybe? |
|
|
| Report Abuse |
|
|
|
| 06 Dec 2011 02:39 PM |
Or here's a way without coroutine:
for _,v in pairs(game.Players:GetPlayers()) do m=Instance.new("Message",v.Character) m.Text="Text" end wait(8) m.Parent=nil |
|
|
| Report Abuse |
|
|
Spectrumw
|
  |
| Joined: 04 Aug 2009 |
| Total Posts: 13510 |
|
|
| 06 Dec 2011 02:42 PM |
@Penguine That will only set the last message's parent to nil. |
|
|
| Report Abuse |
|
|
blockoo
|
  |
| Joined: 08 Nov 2007 |
| Total Posts: 17202 |
|
|
| 06 Dec 2011 02:42 PM |
@Penguine How is that any different from the original? |
|
|
| Report Abuse |
|
|
|
| 06 Dec 2011 02:42 PM |
Pretty much the same thing as using a coroutine, but simpler for newer scripters.
for _,v in pairs(game.Players:GetPlayers()) do local msg = Instance.new("Message", v.PlayerGui) m.Text="Test" game:GetService("Debris"):AddItem(msg, 8) end
"I WILL GIVE YOU BACON." - Deadmau5 ~Scarfacial |
|
|
| Report Abuse |
|
|
|
| 06 Dec 2011 02:42 PM |
@Spect
And yours will spam the player's screen. |
|
|
| Report Abuse |
|
|
|
| 06 Dec 2011 02:45 PM |
| oh wait sry i messed up. you could do another for loop to remove the message. |
|
|
| Report Abuse |
|
|
|
| 06 Dec 2011 02:46 PM |
@Scar
Thanks, seems to be the right one.
@Spect
Wups, I changed something to make it spam. Yea, your script works also fine.
Thanks all, I get the drift. |
|
|
| Report Abuse |
|
|
|
| 06 Dec 2011 03:11 PM |
If you want to practice with tables even more, you could do something like this:
local messages = {}; for _, v in pairs(game.Players:GetPlayer()) do table.insert(messages, Instance.new("Message", v.PlayerGui)); messages[_].Text = "Test"; end wait(5); for _, v in pairs(messages) do v.Parent = nil; end
Cheers, -- AFF |
|
|
| Report Abuse |
|
|
|
| 06 Dec 2011 03:12 PM |
Of course, that's assuming you use the GetPlayers method instead of GetPlayer... >_<
Cheers, -- AFF |
|
|
| Report Abuse |
|
|
|
| 06 Dec 2011 03:23 PM |
| GetPlayers and GetPlayer had a difference? |
|
|
| Report Abuse |
|
|
|
| 06 Dec 2011 03:23 PM |
GetPlayer doesn't exits. ;D
Cheers, -- AFF |
|
|
| Report Abuse |
|
|
|
| 06 Dec 2011 03:24 PM |
Exist*
I cannot type anymore ....
Cheers, -- AFF |
|
|
| Report Abuse |
|
|