I have this line of code here:
while plr.leaderstats == nil do wait() end
It's supposed to wait for the leaderstats to load in before running the rest of the code after. I thought of doing :WaitForChild() , but that only gives me a warning message saying 'infinite yield possible'.
The leaderstats is created in another script, and to prevent the code attempting to look for the leaderstats inside the player before it's created I had this while loop wait until it's not equal to nil.
But now I essentially have two problems right now
Problem
Why am I getting the error 'leaderstats is not a valid member of Player'
(im checking for if it's nil so in that case it's true so it should just proceed to wait right?)
and
How do I avoid 'infinite yield possible' when using :WaitForChild()?
Is there a better way of waiting for certain parts to load?
i feel like the way im approaching this is making it more difficult than it should be

2 comments
Still getting the error that it doesn't exist. I checked for spelling, so that's not the issue.
If you're still getting the error, I'm not sure it is the single line in the script that is at error. Can you check and see if your variables are appropriately defined? For example, the "plr" variable should be pointed towards the Player in the Player Service and not the workspace/character.