Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Script is running faster than startergui can put gui inside player?

Asked by
Azuc 112
7 years ago

So I keep getting an error telling me "Main" is not part of the playergui. I added a line of code to the main script to tell it to wait until it is but it still gives me that error each time. Its like the script is running faster than the startergui can put the gui "Main" in the player

001local PlayerBase = game:GetService("Players")
002        PlayerBase.PlayerAdded:connect(function(PlayerUI)
003    repeat wait() until PlayerUI.PlayerGui:WaitForChild("Main")
004end)
005 
006 
007--// Tables
008 
009winners = {}
010 
011--// Modules
012 
013Settings = require (script.Settings)
014 
015--// Game Variables
View all 161 lines...
0
Try putting the repeat at the very top so none of the code will even run without it. SimpleFlame 255 — 7y
0
(Assuming your game is FE) If this is in a script then the client's PlayerGui is empty from the server LaeMVP 0 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

I see the problem, when you are calling the PlayerAdded event, Lua will execute the code inside of that event and nothing else. Lets say you want to add a WaitForChild() code in the PlayerAdded event (which you did lol) it will only wait for the child and move on, not passing it on to the that script. So I would advice you to change every .Main to :WaitForChild("Main").

Example;

1Player.PlayerGui:WaitForChild("Main")
2--or--
3Player[i].PlayerGui:WaitForChild("Main") --the [i] depends if you are using a for loop

Hope this helped!

TIP: I would advise to hold Ctrl + H (for Windows, but for Mac; Command + H), a frame will appear on the top right hand corner of your screen and you will tell why I said that ;)!

Ad

Answer this question