Why is this always resulting in an infinite yield?

for _,v in pairs(script.Parent:GetChildren()) do
	
	if v.Name=="Eat" and v:IsA("Part") then
		
		v.ProximityPrompt.Enabled=true
		v.ProximityPrompt.Triggered:Connect(function()
			if obj.Value==1 then
				obj.Value+=1
				v.ProximityPrompt.Enabled=false
				script.Parent.Drink:WaitForChild("ProximityPrompt").Enabled=true
			
			end
					
		end)
	else
		v:WaitForChild("ProximityPrompt").Enabled=false--this is causing the warning
	end
end

Line 19 is causing this warning to occur, and I have no idea how to fix it.

the hierarchy is literally just this
image

See this here:

Your problematic line is in the else block, which means it will only run if the if statement condition evaluates to false. Let’s take a closer look at the conditional:

v.Name=="Eat" and v:IsA("Part")

In order for this to be true, v needs to be called “Eat” and it needs to be a part. That means, that for it to be false, it can be because v isn’t called “Eat”, or more importantly, if v isn’t a part.

Basically, the way you structured the conditional means that the else block will run if v isn’t a part. And looking at your hierarchy, there is indeed something that isn’t a part; the script itself. So now that line in the else block is looking for a ProximityPrompt inside the script itself, which does not exist, hence the infinite yield.

2 Likes

I just found that out too. However, the problem isn’t that, and the output always prints out: “Infinite yield possible on 'Workspace.Model.Script:WaitForChild(“ProximityPrompt”)'” whenever I run the game. The proximity prompts are indeed there, so I have no idea what’s going on.

Did you even read what I said, and also yes that is the problem. You just proved it for me because the error message literally tells you that it is trying to find a ProximityPrompt INSIDE THE SCRIPT

No, you don’t get it. I have removed the :IsA(“Part”) and the “and” condition, but for some reason, IT STILL DOES NOT WORK!


The Wash prompt is supposed to appear last, but when I joined, it is enabled. Code has no effect on it.

Also, I am very inexperienced with coding, so please excuse my horrendous coding skills.

You don’t understand how booleans work do you. THAT DOES NOT FIX IT. You’re just making it worse, because now it will try to find a ProximityPrompt in anything that isn’t called “Eat”.

You need to first make sure what you’re dealing with is actually a part first. So you check to see if it’s a part and do nothing else if it isn’t.

if v:IsA('Part') then
	if v.Name=="Eat" then
		v.ProximityPrompt.Enabled=true
		v.ProximityPrompt.Triggered:Connect(function()
			if obj.Value==1 then
				obj.Value+=1
				v.ProximityPrompt.Enabled=false
				script.Parent.Drink:WaitForChild("ProximityPrompt").Enabled=true

			end

		end)
	else
		v:WaitForChild("ProximityPrompt").Enabled=false--this is causing the warning
	end
end
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.