✓ Accepted answer
This is happening because you get the children of the Players service as soon as the script runs. The player likely hasn't finished loading in at this point. You can do a few things to avoid this, such as moving where Players is defined:
function GUIUpdate (Type,Message)
if Type == 'All' then
print("ALL")
local Players = game:GetService("Players"):GetPlayers();
for _,v in pairs(Players) do
print(v.Name)
print("for")
v.PlayerGui.Status.FR.txtbox.Text = Message
end
end
end
GUIUpdate ('All',"Not enough players!")
While that fixes future issues with the function, it doesn't change the fact that it likely won't enter the loop. This is because you call GUIUpdate immediately as well. You can wait for a player to join using thePlayerAdded event of Players:
local PlayersService = game:GetService("Players");
function GUIUpdate (Type,Message)
if Type == 'All' then
print("ALL")
local Players = PlayersService:GetPlayers();
for _,v in pairs(Players) do
print(v.Name)
print("for")
v.PlayerGui.Status.FR.txtbox.Text = Message
end
end
end
PlayersService.PlayerAdded:Wait()
GUIUpdate ('All',"Not enough players!")
This should wait until a player has joined the game before updating. I assume you intend to use this differently and it's only in this form for testing; this function will only run once and won't continually check if there are enough players. You can check that using a while loop, among other methods.
You should also avoid changing players' GUIs in server scripts, use remote events for that.
Hope this helped.
Read more about GetPlayers.
2 comments
Thank you! I was really stumped there.
No problem.