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

Question about waiting for player?

Asked by
Relatch 550 Moderation Voter
9 years ago

I am having problems lately with my scripts because I have to add a wait before using my scripts. I was wondering if there was a way to wait for the player to load before the script starts.

I think it would start like this:

repeat wait() until

After until, I have no idea what comes next. Help?

2 answers

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

You need to wait (usually) for the presence of their Character (since this is one of the last things to load).

player = game.Players.LocalPlayer -- Don't have to wait for this!

repeat
    wait()
until player.Character
-- Do have to wait for their Character!

0
Workspace.Script:2: attempt to index global 'player' (a nil value) Relatch 550 — 9y
1
This is for a LocalScript... fahmisack123 385 — 9y
Ad
Log in to vote
0
Answered by 9 years ago
local player = game.Players.LocalPlayer
repeat wait() until player.Character

Similarly, you can replace line 2 with this:

repeat wait() until player.Character~=nil
0
Player is not a valid member of DataModel. Relatch 550 — 9y
0
Must be in a LocalScript in the StarterGui/StarterPack. Spooce 78 — 9y
0
You do *not* need to wait for LocalPlayer. You *do* need to wait for their *Character*. In addition, *THIS CODE WON'T WORK*. You aren't recomputing `player` so the condition will never change. BlueTaslem 18071 — 9y
0
Edited my answer. Thanks Blue. SlickPwner 534 — 9y

Answer this question