Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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

5 comments

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

0

I just did that :P

0

To solve you're problem there is a function in a player called 'CharacterAdded', i highly suggest u to use it :P

0

Ok, thanks for the advice!

0

No problem, glad i actually helped you with something :D

This discussion is preserved as it was. New answers, comments, and votes are closed.