I'm doing a test script to play around with for loops & looping through available players. The script is simple!
print("Script initiated.")
function Run()
for i, v in ipairs(game.Players:GetPlayers()) do -- Get available players!
wait(12); -- In case contents inside PlayerGui has not been loaded!
print(v); -- Prints the current iteration, player's name (current iteration).
print(game.Players[v.Name].PlayerGui.testFind); -- Simple, there's a ScreenGui!
end
end
game.Players.PlayerAdded:connect(Run)
Very simple. Yet doesn't work. Why!?
It works in studio and this is what it outputs:
Script initiated.
Player1
testFind
However if you try it online, there's suddenly an error!
Script initiated.
Player... added
Arithmeticity
testFind is not a valid member of PlayerGui
The script is placed in ServerScriptStorage.
Here's the model if you want to take a look at it and see why: click to see the model.
Am I missing something? Please help me as this is confusing me. It should be e-z-p-z.
Update(s):
Just got helped by ScriptGuider. He says that server cannot access the contents of PlayerGui so that may be a possibility. I'm now trying to work around it instead of doing this method. See how it goes and all, so far so good. Thanks to ScriptGuider! If ScriptGuider reads this, maybe post a reply so I can accept your answer perhaps.
Edited the script yet again to include WaitForChild. Here it is:
print("Script initiated.")
function Run()
for i, v in ipairs(game.Players:GetPlayers()) do
print(v);
game.Players[v.Name].PlayerGui:WaitForChild("testFind");
print(game.Players[v.Name].PlayerGui.testFind);
end
end
game.Players.PlayerAdded:connect(Run)
Output has been changed, it's now this:
Script initiated.
Arithmeticity.
Player ... added
Infinite yield possible on 'Players.Arithmeticity.PlayerGui:WaitForChild("testFind")'
Stack Begin
Script 'ServerScriptService.testIterations', Line 5
Stack End
I have also updated the model so if anyone can please take it and take a look in their own game, that'll be really helpful!
Past edit 2/1/2017:
print("Script initiated.")
function Run()
for i, v in ipairs(game.Players:GetPlayers()) do
print(v);
repeat wait() until game.Players[v.Name].PlayerGui.testFind;
print(game.Players[v.Name].PlayerGui.testFind);
end
end
game.Players.PlayerAdded:connect(Run)
The output is pretty much the same results. Why is this happening!?

6 comments
Are you trying to do something to every player every time a player joins, or just do something to the player that just joined?
Commented
I'm not sure but i think you should try making it a local script and putting it into game.StarterPlayer.StarterPlayerScripts
@Nogalo, that defeats the purpose of what I'm trying to do. Do you not have a solution?
Why're you typing "game.Players[v.Name]" when "v" is the player returned?
Is the GUI even being put into the PlayerGui? If it's a script placing it there, please show it.