I am highly assuming you are running this in a Server Side script, under Workspace or ServerScriptService. The reason it is not looping to all player's ScreenGuis is because of this wait() functions. Seriously, that's the problem. I know this because I have tried making a admin script and a laser tag game looping through all players using the same method presented. The way you can have the script loop through all players at once while not removing the waits if a technique called coroutines. Coroutines basically makes lines of code in a function to run almost like a separate script is being used (that's my best explanation of it). For your script you will want to use the following code:
1 | coroutine.resume(coroutine.create( function () |
With coroutines, the wait time will do the wait for that player only. It is a useful technique especially if you know your script may break, due to a person leaving or something along those lines, the coroutine will break but the entire script will not. Though, caution when using coroutines because any errors will be hidden from the developer console.
As a final output your script should look like this when looping through players.
04 | local LSounds = game.Lighting.LoseSounds:GetChildren() |
05 | local WSounds = game.Lighting.WinSounds:GetChildren() |
06 | local Maps = game.Lighting.Maps:GetChildren() |
09 | if game.Players.NumPlayers > 1 then |
10 | for i,v in pairs (game.Players:GetChildren()) do |
11 | coroutine.resume(coroutine.create( function () |
12 | v.PlayerGui.TopBar.Frame.Visible = true |
13 | v.PlayerGui.TopBar.Frame.TextLabel.Text = "Intermission..." |
15 | v.PlayerGui.TopBar.Frame.TextLabel.Text = "Choosing Map..." |
19 | local MapChoose = math.random( 1 , #Maps) |
20 | local MapChosen = Maps [ MapChoose ] |
21 | for i,v in pairs (game.Players:GetChildren()) do |
22 | coroutine.resume(coroutine.create( function () |
23 | v.PlayerGui.TopBar.Frame.TextLabel.Text = "Map Found!" |
25 | v.PlayerGui.TopBar.Frame.TextLabel.Text = "Loading map..." |
27 | v.PlayerGui.TopBar.Frame.TextLabel.Text = "Loading map... " ..i.. "%" |
30 | v.PlayerGui.TopBar.Frame.TextLabel.Text = "Map Loaded!" |
33 | MapChosenClone = MapChosen:Clone(game.Workspace) |
35 | for i,v in pairs (game.Players:GetChildren()) do |
37 | v:WaitForChild( "PlayerGui" ).TopBar.Frame.Visible = true |
38 | v:WaitForChild( "PlayerGui" ).TopBar.Frame.TextLabel.Text = "There must be Another Player in order to Play this Game" |
Some people may complain that coroutine.wrap()
is more efficient, but I don't use it since I have not had much luck with it. Though I have seen coroutine.wrap()
go coroutine.wrap(function --Code end)()
in another script, which I haven't tried yet but will intend on doing.
Hopefully this answer helped and explained what coroutines are a bit, and hope that they help in the long run. If you need a further explanation to coroutines, checkout this wiki article.