Infinite yield error

Hey everyone, testing a new chatservice for a new map used for a clan and I keep being meant with this error.
Infinite Yield possible on ‘ServiceScriptService:WaitForChild(“ChatServiceRunner”)’

local DIRE = 871005653
local STANDARD_COLOR = Color3.fromRGB(18, 238, 212)

local ServerScriptService = game:GetService("ServerScriptService")
local Players = game:GetService("Players")
local Chat = game:GetService("Chat")

local ChatService = require(ServerScriptService:WaitForChild("ChatServiceRunner"):WaitForChild("ChatService"))

function GetTags(player: Player, speaker)
	local tags = {}
	local rank = player:GetRankInGroup(34026213)
	
	local function AddTag(text: string, color: Color3)
		table.insert(tags, {TagText = text, TagColor = color})
	end

	local function AddIcon(id: number, color: Color3)
		table.insert(tags, {TagImage = "rbxassetid://" .. id, TagColor = color})
	end

	local function SetChatColor(color: Color3)
		speaker:SetExtraData('ChatColor', color)
	end
	
	if player.UserId == DIRE or player:GetRankInGroup(34026213) == 250 then -- Dire's/Highlord's custom
		AddIcon(9477205088, Color3.fromRGB(148, 0, 0)) -- 148, 0, 0
		SetChatColor(Color3.fromRGB(212, 106, 108)) -- 212, 106, 108
		return tags
	end

	-- Tal'darim tag
	local taldarimRank = player:GetRankInGroup(34026213)
	if taldarimRank > 0 and taldarimRank <= 254 then
		AddIcon(9362626867, Color3.fromRGB(170, 64, 66))
	end
	
	-- Shadow Guard tag
	local shadowRank = player:GetRankInGroup(14519836)
	if shadowRank > 20 and shadowRank <= 220 then
		AddIcon(9362626777, Color3.fromRGB(0, 0, 121))
	end

	-- Nerazim tag
	local nerazimRank = player:GetRankInGroup(6215166)
	if nerazimRank > 0 and nerazimRank <= 252 then
		AddIcon(9362626777, Color3.fromRGB(72, 207, 97))
	end

--	local phaseRank = player:GetRankInGroup(6196473)
--	if (phaseRank > 0 and phaseRank < 253) or phaseRank == 255 then
--		AddIcon(9362627332, Color3.fromRGB(233, 30, 99))
--	end

	if rank == 255 then -- Hierarch
		AddIcon(9477205088, Color3.fromRGB(225, 0, 225))
		SetChatColor(Color3.fromRGB(225, 0, 225))
	elseif rank == 250 then -- Vice Hierarch
		AddIcon(9362627332, Color3.fromRGB(233, 30, 99))
		AddIcon(9477205088, Color3.fromRGB(148, 0, 211))
	elseif rank == 220 then -- Executor
		AddIcon(9477205088, Color3.fromRGB(0, 170, 255))
	elseif rank == 200 then -- Patriarch
		AddIcon(9477205088, Color3.fromRGB(255, 215, 0))
	elseif rank == 190 then -- Praetor
		AddIcon(9477205088, Color3.fromRGB(225, 188, 0))
	elseif rank == 180 then -- Prelate
		AddIcon(9477205088, Color3.fromRGB(225, 188, 0))
	elseif rank == 19 then -- Phasesmith
		AddIcon(9362627332, Color3.fromRGB(233, 30, 99))
	elseif rank == 18 then -- Judicator
		AddIcon(9477205088, Color3.fromRGB(255, 24, 0))
	elseif rank == 17 then -- High Templar
		AddIcon(9477205088, Color3.fromRGB(231, 76, 60))
	elseif rank == 16 then -- Templar
		AddIcon(9477205088, Color3.fromRGB(231, 76, 60))
	elseif rank == 13 then -- Entaro Fallen
		AddTag('En Taro', Color3.fromRGB(233, 195, 219))
	elseif rank == 12 then -- Oracle
		AddIcon(9477205088, Color3.fromRGB(50, 216, 119))
	elseif rank >= 10 then -- MR
		AddIcon(9477205088, Color3.fromRGB(36, 155, 86))
	end
	
	return tags
end

ChatService.SpeakerAdded:Connect(function(playerName)
	local speaker = ChatService:GetSpeaker(playerName)
	local player = speaker:GetPlayer()

	-- Tags
	if player then
		speaker:SetExtraData('Tags', GetTags(player, speaker))
	end
end)
3 Likes

Are you sure it’s the right script?
The error message says it’s in line 8, which is an end in this script.

1 Like

Yea you’re right, it was the wrong paste. `

local DIRE = 871005653
local STANDARD_COLOR = Color3.fromRGB(18, 238, 212)

local ServerScriptService = game:GetService("ServerScriptService")
local Players = game:GetService("Players")
local Chat = game:GetService("Chat")

local ChatService = require(ServerScriptService:WaitForChild("ChatServiceRunner"):WaitForChild("ChatService"))

function GetTags(player: Player, speaker)
	local tags = {}
	local rank = player:GetRankInGroup(34026213)
	
	local function AddTag(text: string, color: Color3)
		table.insert(tags, {TagText = text, TagColor = color})
	end

	local function AddIcon(id: number, color: Color3)
		table.insert(tags, {TagImage = "rbxassetid://" .. id, TagColor = color})
	end

	local function SetChatColor(color: Color3)
		speaker:SetExtraData('ChatColor', color)
	end
	
	if player.UserId == DIRE or player:GetRankInGroup(34026213) == 250 then -- Dire's/Highlord's custom
		AddIcon(9477205088, Color3.fromRGB(148, 0, 0)) -- 148, 0, 0
		SetChatColor(Color3.fromRGB(212, 106, 108)) -- 212, 106, 108
		return tags
	end

	-- Tal'darim tag
	local taldarimRank = player:GetRankInGroup(34026213)
	if taldarimRank > 0 and taldarimRank <= 254 then
		AddIcon(9362626867, Color3.fromRGB(170, 64, 66))
	end
	
	-- Shadow Guard tag
	local shadowRank = player:GetRankInGroup(14519836)
	if shadowRank > 20 and shadowRank <= 220 then
		AddIcon(9362626777, Color3.fromRGB(0, 0, 121))
	end

	-- Nerazim tag
	local nerazimRank = player:GetRankInGroup(6215166)
	if nerazimRank > 0 and nerazimRank <= 252 then
		AddIcon(9362626777, Color3.fromRGB(72, 207, 97))
	end

--	local phaseRank = player:GetRankInGroup(6196473)
--	if (phaseRank > 0 and phaseRank < 253) or phaseRank == 255 then
--		AddIcon(9362627332, Color3.fromRGB(233, 30, 99))
--	end

	if rank == 255 then -- Hierarch
		AddIcon(9477205088, Color3.fromRGB(225, 0, 225))
		SetChatColor(Color3.fromRGB(225, 0, 225))
	elseif rank == 250 then -- Vice Hierarch
		AddIcon(9362627332, Color3.fromRGB(233, 30, 99))
		AddIcon(9477205088, Color3.fromRGB(148, 0, 211))
	elseif rank == 220 then -- Executor
		AddIcon(9477205088, Color3.fromRGB(0, 170, 255))
	elseif rank == 200 then -- Patriarch
		AddIcon(9477205088, Color3.fromRGB(255, 215, 0))
	elseif rank == 190 then -- Praetor
		AddIcon(9477205088, Color3.fromRGB(225, 188, 0))
	elseif rank == 180 then -- Prelate
		AddIcon(9477205088, Color3.fromRGB(225, 188, 0))
	elseif rank == 19 then -- Phasesmith
		AddIcon(9362627332, Color3.fromRGB(233, 30, 99))
	elseif rank == 18 then -- Judicator
		AddIcon(9477205088, Color3.fromRGB(255, 24, 0))
	elseif rank == 17 then -- High Templar
		AddIcon(9477205088, Color3.fromRGB(231, 76, 60))
	elseif rank == 16 then -- Templar
		AddIcon(9477205088, Color3.fromRGB(231, 76, 60))
	elseif rank == 13 then -- Entaro Fallen
		AddTag('En Taro', Color3.fromRGB(233, 195, 219))
	elseif rank == 12 then -- Oracle
		AddIcon(9477205088, Color3.fromRGB(50, 216, 119))
	elseif rank >= 10 then -- MR
		AddIcon(9477205088, Color3.fromRGB(36, 155, 86))
	end
	
	return tags
end

ChatService.SpeakerAdded:Connect(function(playerName)
	local speaker = ChatService:GetSpeaker(playerName)
	local player = speaker:GetPlayer()

	-- Tags
	if player then
		speaker:SetExtraData('Tags', GetTags(player, speaker))
	end
end)
1 Like

Ensure you are using LegacyChatService instead of TextChatService.

1 Like

And remember that WaitForChild will timeout after just 5 seconds according to the documentation.

1 Like

An infinite yield warning is essentially the program waiting (yielding) for an object to be found, but is still not found after a period of 5 seconds. As mentioned by @Scottifly, this is caused by the use of :WaitForChild(). In summary, :WaitForChild() will hold (yield) the program until the parameter (the value inside of the brackets) is found. It will continue to yield the program until that object is found, and if it cannot be found then it will essentially hold the program infinitely, hence the name infinite yield.

For example, if you are using :WaitForChild() to find the object carPart1 in Workspace, but provided the parameter with game.ReplicatedStorage.carPart1, the program will continue waiting for that object to be found within ReplicatedStorage, since the object is found inside of Workspace, the program will be yielding indefinitely.

I would suggest that you revisit your :WaitForChild() methods and ensure that the parameter given is found within your game.

True, but keep in mind for anybody reading this you can add the 2nd parameter to specify the wait time in any of them SoSoSo:WaitForChild(Whateverwhatever, 10 -- Or whatever wait time you want here) EDIT: Wrong reply, I meant to reply to the one above

1 Like