Infinite yield possible on Players:WaitForChild('LocalPlayer')?

Why is it doing that

Players.LocalPlayer is a property of Players not a child. Functions like FindFirstChild and WaitForChild wont return a valid result. When a client script runs you don’t have to wait for the LocalPlayer anyway.


Localplayer is only a local script feature. It is also not an instance so WaitForChild: Would not work on it.
If you’re trying to get the local player just use game.Players.LocalPlayer

It’s a property of game.Players not a child / instance

If you need to use a server script then just try to find another way to do so with events etc.


you cant get the local player from a module script so it will just infinite yield because theres nothing to find


So I did that. Then I printed it on the next line under because I was curious, but it printed nil?

I think it is because the player has not loaded into the game, and that’s why it prints nil. But if that is the case, how else could I do about defining player inside the module script

So why is the player nil?

That script shows that it’s running on the server which has no LocalPlayer instance. You need to run it on the client instead for LocalPlayer to be present.


But that other guy just said you don’t need to wait for player’s inside module scripts

That’s unrelated to my point.

LocalPlayer will always be nil on the server because the server does not have its own player instance, only the players connected to it.

You need to use a script running on the client (either a LocalScript or a ModuleScript required by a LocalScript) to read it.


I was mentioning LocalScripts not ModuleScripts. For module scripts LocalPlayer only exists when they are called from a client script.


It’s because you are using a server script to do so.
If you try to get local script with a server script it would just count as nil. Localplayer only works in local scripts

You don’t have to wait for a localplayer since if it’s in a local script it would work on the client anyways which means it would just instantly get the local player. but if it’s in a serverscript it would not get localplayer

1 Like

Try printing “player.Name” instead of “player”.