Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

[Infinite yield error] Team change on death?

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        character:WaitForChild("Humanoid").Died:Connect(function()
            print(player.Team.Name)
            if player.Team.Name == "Blue" then
                player.Team = game.Teams:WaitForChild("Red")
            else
                player.Team = game.Teams:WaitForChild("Blue")
                wait(0.5)
            end
        end)
    end)
end)

I made this script is so that when a players dies it will switch the player to the other team. In this case when the player dies on blue then he will be switched to red , vice versa.

But when I die it runs , the problem is that the output gives me this error "Infinite yield possible on 'Teams:WaitForChild("Blue")"

The line 6 and 9 line is to change or set the players team , could there be anything wrong there?

1 answer

✓ Accepted answer

Here! Merry christmas! :)

game.Players.PlayerAdded:Connect(function(PLR) -- On player added connect function
    PLR.CharacterAdded:Connect(function(CH) -- On character added connect function
        CH:WaitForChild("Humanoid").Died:Connect(function() -- On player death connect function
            print(PLR.Team.Name) -- Prints the player's team
            if PLR.Team.Name == "Blue" then -- If the player's team is blue then
                PLR.TeamColor = game.Teams:WaitForChild("Red").TeamColor -- Sets the player's team color to the team's team color
                PLR.Neutral = false -- Makes the player not neutral so the player's username in chat will appear red
            else
                PLR.TeamColor = game.Teams:WaitForChild("Blue").TeamColor -- Sets the player's team color to the team's team color
                PLR.Neutral = false -- Makes the player not neutral so the player's username in chat will appear blue
            end
        end)
    end)
end)

4 comments

0

It still doesnt change but just gives me the same infinite yield error.

0

That's weird.

0

That's weird.

0

Nvm I found another method its about remote events thanks anyways!

This discussion is preserved as it was. New answers, comments, and votes are closed.