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

(ReplicatedFirst) How to wait for the character to load?

Asked by 7 years ago

I'm trying to make my script wait until the character loads. I attempted to do..

game.Players.PlayerAdded:wait() --and..
game.Players.ChildAdded:wait()

..but neither of the functions fired. Probably fired before the character joined the game.

--In "ReplicatedFirst"
local Player = game.Players.???
local PlayerGui = Player.WaitForChild('PlayerGui')
local ScreenGui = PlayerGui:WaitForChild('ScreenGui')
local Loading = Instance.new('TextLabel',ScreenGui)
Loading.Text = 'Loading...'
Loading.BackgroundTransparency = 0.5
Loading.BackgroundColor = BrickColor.new(0,0,0)
Loading.Size = UDim2.new(1,0,1,0)
Loading.Font = 'SciFi'
Loading.Name = 'Loading'

Is there any other way to get the player name so I can just do game.Players:WaitForChild(LocalPlayer)?

1 answer

Log in to vote
2
Answered by
Valatos 166
7 years ago
Edited 7 years ago

You would get the player name by doing this

local player = game.Players.LocalPlayer
local player_name = player.Name

This only works in LocalScripts!

Also, you used

Gui.BackgroundColor = BrickColor.new()

That's wrong, you would need to use a Color3

Gui.BackgroundColor = Color3.new(0, 0, 0)

I saw you wanted it to be black, so i did that already

The final code

local Player = game.Players.LocalPlayer

player.CharacterAdded:wait() -- Waiting for the character to spawn! :D

local PlayerGui = Player.WaitForChild('PlayerGui')
local ScreenGui = PlayerGui:WaitForChild('ScreenGui')
local Loading = Instance.new('TextLabel',ScreenGui)
Loading.Text = 'Loading...'
Loading.BackgroundTransparency = 0.5
Loading.BackgroundColor = Color3.new(0, 0, 0)
Loading.Size = UDim2.new(1,0,1,0)
Loading.Font = 'SciFi'
Loading.Name = 'Loading'

A wiki page for Color3

Hope i helped!

~jordikeijzers

0
My question was if you could make some type of wait() until the Player instance appeared. The reason why I am doing this is because sometimes I get an error online that LocalPlayer doesn't exist, so I try to make something to wait. I don't think there's a way to do that. I'll just do: while true do wait() if game.Players.LocalPlayer then break end end fighter169mobile 123 — 7y
0
I just did that :P Valatos 166 — 7y
0
To solve you're problem there is a function in a player called 'CharacterAdded', i highly suggest u to use it :P Valatos 166 — 7y
0
Ok, thanks for the advice! fighter169mobile 123 — 7y
0
No problem, glad i actually helped you with something :D Valatos 166 — 7y
Ad

Answer this question