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)
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:
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.