I made a method that triggers if there isn't enough players on the game called AnnounceMsg()
. It takes in a string that announces a message. Here is the function:
function AnnounceMsg(message) for _, player in pairs (game.Players:GetChildren()) do player:WaitForChild("PlayerGui").Announcements.Backing.Announcements.Text = message end end
I am getting the error:
Announcements is not a valid member of PlayerGui
BUT! The problem is it is a member of PlayerGui. Any help?
Problem
The only problem I can see is that since it works in studio and not in server it should be a latency problem, this happens because in studio everything is pretty much local so you don't have to wait for a server to create stuff so your local scripts run instantly. In server this doesn't happen as when a local scripts cause upons something in player or character that is server-sided then the local script is "local" which makes it run faster then the server can respond.
Solution
repeat wait() until game.Players.LocalPlayer.Character--To the top of every local script
Ah, your game is FilteringEnabled. You can only access a player's PlayerGui serversided. Meaning, the script will have to be a server script (normal, not local), and placed in ServerScriptService. To cooperate with FilteringEnabled, I recommend looking into the RemoteEvents and RemoteFunction tutorial.