How can I prevent this infinite yield warning?

Hi there! I’m currently just making something for fun, and I’m trying to call to a folder inside the player [when you’re in studio: Players > srauf1 > PlayerValues].


	PromptPart.Touched:Connect(function(Hit)
		local Humanoid = Hit.Parent:FindFirstChild("Humanoid")
		if Humanoid then
			local PlayerValues = Humanoid.Parent:WaitForChild("PlayerValues")

I assume this is what prevents the rest of the script [which seems unnecessary to present at the minute, as it probably has nothing to do with the warning considering I got it beforehand.

The warning I receive:
Infinite yield possible on 'Workspace.srauf1:WaitForChild("PlayerValues")' - Studio

I’m not sure if there’s an issue with how I’m calling for ‘PlayerValues’, but I’d just love to learn how to fix it.

Thanks!

Edit: It says ‘Workspace.srauf1’, where the folder isn’t located in the Workspace. How can I access the actual ‘Player’, if you know what I mean. :stuck_out_tongue:

Double edit: I realise it only says Workspace because Humanoid.Parent would be the Player Character model in the Workspace. However, when I change it to Player from a PlayerAdded function, I receive the same warning.

'Infinite yield possible on ‘Players.srauf1:WaitForChild(“PlayerValues”)’

2 Likes

If you’re trying to get something inside of the player’s player instance, then you can use the GetPlayerFromCharacter function of the Players service, giving it the parent of the thing that touched the part

PromptPart.Touched:Connect(function(Hit)
	local player = game:GetService("Players"):GetPlayerFromCharacter(Hit.Parent)
	if player then
		local PlayerValues = player:WaitForChild("PlayerValues")

Which returns the player isntance if it found one using the Character given or nil if it hasn’t

Also be certain you gave the right name as it may still give the same error otherwise

2 Likes

I’ll give this a go and mark your reply as ‘Solution’ if it works! Thanks.

1 Like

Yeah this is possible, since the mesh part of a hat can also be a hit.

Hi Embat! Tried your script out:


PromptPart.Touched:Connect(function(Hit)
	local Player = game:GetService("Players"):GetPlayerFromCharacter(Hit.Parent)
	if Player then
		local PlayerValues = Player:WaitForChild("PlayerValues")

It returns the same error:
`Infinite yield possible on ‘Players.srauf1:WaitForChild(“PlayerValues”)’ - Studio’

The folder is definitely called 'PlayerValues!
(I don’t know if it’s relevant to the problem, but it takes like 5 seconds for it to return the warning after the PromptPart is touched)

Okay, now anotehr question, is this PlayerValues folder created instantly, or is created at some point in the game? IF it’s made instantly then the name is incorrect or it’s taking a very long tiem to load

It’s there from the moment the player goes past the Roblox default loading screen. (This:)

Okay, could you show me how it looks in the explorer

Ignore that I covered the username, I develop on a separate account.
image

Okay now I’m really confused, nothing should be causing that warning as it exists. And I think directly indexing would cause an error. Try double checking the names to ensure their exact? Copy and paste the PlayerValues in your script and paste it where it makes the folder?

Something else has to be going on, look through everything related to it and if there’s some small mistake?

The only thing I can think of is if it needs a debounce or anything?
It takes 5 seconds for the warning to appear in Output after touching. I’ll check the scripts now.

Edit: Nope, no spelling errors.

Okay 2nd question, is the Folder being made on the client? Aka is the Touched event on a server script and the Folder creation on a localscript?

Yes, that’s the case.
If that’s the error, than that’s a big whoops on my side for not knowing it would cause that, haha. :sweat_smile:

Yep that’s why then, only the client can see the folder, the server doesn’t notice it existing. I think you need to make the folder from a regular script.

1 Like