Infinite yield even though BoolValue is in backpack

The code keeps freezing, returning a Infinite yield error when I can clearly see it in explorer in my player’s backpack. I have tried many things, such as waiting for it until it loads in (but it never finds it) and have tried using it on the client, which returns the same result.

local GK1 = game:GetService("Teams")["1GK"]
local GK2 = game:GetService("Teams")["2GK"]

game:GetService("Players").PlayerAdded:Connect(function(player)
	local backpack = player:WaitForChild("Backpack")
	local GK = backpack:WaitForChild("Goalkeeper")
	while true do
		if player.Team == GK1 or GK2 then
			GK.Value = true
		else
			GK.Value = false	
		end
	wait()
	end
end)

Why are you placing BoolValues in the player’s backpack though? The backpack is meant for tools. :thinking:

It’s to my knowledge the easiest way to check from an individual player if they meet the condition.

I personally think that placing values in the player is more convenient. Also I noticed that here you wrote:

if player.Team == GK1 or GK2 then

This would basically ask the system if the player is in team GK1 or if GK2 is true or not nil. If you wanted to check if the player was in either of the teams:

if player.Team == GK1 or player.Team == GK2 then
1 Like

This is quite weird. Can you try waiting for the character to load also and then continue with your code?

game:GetService("Players").PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(char)
	    local backpack = player:WaitForChild("Backpack")
	    local GK = backpack:WaitForChild("Goalkeeper")
	    while true do
		    if player.Team == GK1 or GK2 then
			    GK.Value = true
		    else
			    GK.Value = false	
		    end
	        wait()
	    end
    end)
end)

I am curious if the backpack is loaded when the character is added.

1 Like

Thank you so much, this fixed it!

1 Like