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

waiting for a player to load- before you do anything?

Asked by 9 years ago

I want to wait for a player to load, before my code can begin. How do i do this? plz

2
CharacterAdded and wait until more than 8 things are inside of the character. EzraNehemiah_TF2 3552 — 9y
0
^ doesnt sound legit ConnorVIII 448 — 9y
2
^It works though EzraNehemiah_TF2 3552 — 9y

2 answers

Log in to vote
1
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
9 years ago

There's really no point to wait for the Player to load, because the Player will always exist. But you probably meant the Character.

As Hungry mentioned, repeat loops will work fine:

repeat wait() until plr.Character

LordDragon's comment said that this will work:

plr.CharacterAdded:wait()

But you don't want to do this, or at least not only this. The reason for this is that if the character already exists, it will wait until you respawn again, because the event won't fire. A common solution to this is to do the following:

local character = plr.Character or plr.CharacterAdded:wait()

What this does is see if the character already exists, and if it does, assign the variable to it. But if it doesn't exist, then it waits for the CharacterAdded event to fire.

Ad
Log in to vote
3
Answered by 9 years ago
local player = game.Players.Player
repeat wait() until Player.Character

repeats wait() until the character of local player is found.

1
dude there is an easier way, player.CharacterAdded:wait() EzraNehemiah_TF2 3552 — 9y

Answer this question