I'm trying to make my script wait until the character loads. I attempted to do..
1 | game.Players.PlayerAdded:wait() --and.. |
2 | game.Players.ChildAdded:wait() |
..but neither of the functions fired. Probably fired before the character joined the game.
01 | --In "ReplicatedFirst" |
02 | local Player = game.Players.??? |
03 | local PlayerGui = Player.WaitForChild( 'PlayerGui' ) |
04 | local ScreenGui = PlayerGui:WaitForChild( 'ScreenGui' ) |
05 | local Loading = Instance.new( 'TextLabel' ,ScreenGui) |
06 | Loading.Text = 'Loading...' |
07 | Loading.BackgroundTransparency = 0.5 |
08 | Loading.BackgroundColor = BrickColor.new( 0 , 0 , 0 ) |
09 | Loading.Size = UDim 2. new( 1 , 0 , 1 , 0 ) |
10 | Loading.Font = 'SciFi' |
11 | Loading.Name = 'Loading' |
Is there any other way to get the player name so I can just do game.Players:WaitForChild(LocalPlayer)?
You would get the player name by doing this
1 | local player = game.Players.LocalPlayer |
2 | local player_name = player.Name |
This only works in LocalScripts!
Also, you used
1 | Gui.BackgroundColor = BrickColor.new() |
That's wrong, you would need to use a Color3
1 | Gui.BackgroundColor = Color 3. new( 0 , 0 , 0 ) |
I saw you wanted it to be black, so i did that already
The final code
01 | local Player = game.Players.LocalPlayer |
02 |
03 | player.CharacterAdded:wait() -- Waiting for the character to spawn! :D |
04 |
05 | local PlayerGui = Player.WaitForChild( 'PlayerGui' ) |
06 | local ScreenGui = PlayerGui:WaitForChild( 'ScreenGui' ) |
07 | local Loading = Instance.new( 'TextLabel' ,ScreenGui) |
08 | Loading.Text = 'Loading...' |
09 | Loading.BackgroundTransparency = 0.5 |
10 | Loading.BackgroundColor = Color 3. new( 0 , 0 , 0 ) |
11 | Loading.Size = UDim 2. new( 1 , 0 , 1 , 0 ) |
12 | Loading.Font = 'SciFi' |
13 | Loading.Name = 'Loading' |
Hope i helped!
~jordikeijzers