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

Infinite Yield Possible on.... I'm getting 2 of these errors, Help?

So basically, I'm making a murder mystery 2 style game. And during scripting of the game, I have a Main Script that basically is the hub for connecting all little bits of the game. Therefore making a 300 line code. I'll paste the script right below here. My two errors are;

Infinite yield possible on 'ReplicatedStorage:WaitForChild("RemoteEvent")' Infinite yield possible on 'ReplicatedStorage:WaitForChild("StatusTag")'

--Made by Deddlox and ExplodingNightWolf



--times
local roundtime = 60 * 5
local intermissiontime = 20
   
--defining
local serverstorage = game:GetService("ServerStorage")
local replicatedstorage = game:GetService("ReplicatedStorage")
local debris = game:GetService("Debris")
local event = replicatedstorage:WaitForChild("RemoteEvent") 
local maps = serverstorage:WaitForChild("Maps")
local mapholder = game.Workspace:WaitForChild("MapHolder")
local statustag = replicatedstorage:WaitForChild("StatusTag")
local timertag = replicatedstorage:WaitForChild("TimerTag")



--leaderboard/awarding points
function awardpoints (player, points)
	if player and points then 
		local leaderstats = player.FindFirstChild("leaderstats")
		if leaderstats then
			local pointsvalue = leaderstats:FindFirstChild("Points")
			if pointsvalue then
				pointsvalue.Value = pointsvalue.Value + points
			end
		end
	end
end


--net gun for when the detective dies, someone else can pick it up ( do not have to use if. )
function dropnetgun(pos)
	local pickup = serverstorage:WaitForChild("Net Gun"):WaitForChild("Handle"):clone()
	pickup.Name = "Pickup"
	pickup.Anchore = true
	pickup.CanCollide = false
	pickup.CFrame = CFrame.new(pos)
	--what the net gun looks like when on ground, hovering
	local sparkles = Instance.new("Sparkles")
	sparkles.SparkleColor = Color3.new(0, .5, 1)
	sparkles.Parent = pickup
	--clones the net gun so it respawns and doesn't disapear each round
	local given = false
	pickup.Touched:connect(function(hit)
		local humanoid = hit.Parent:FindFirstChild("Humanoid")
		if humanoid and humanoid.Health > 0 then
			local player = game.Players:GetPlayFromCharacter(hit.Parent)
			if player and player ~= slasher then
				local backpack = player:FindFirstChild("Backpack")
				if backpack and not given then
					given = true
					pickup:remove()
					local netgun = serverstorage:WaitForChild("Net Gun"):clone()
					netgun.Parent = backpack
					detective = player
				end
			end
		end
	end)
	--walkspeed/ etc for detective handling the net gun
	for _, player in pairs (game.Players:GetChildren()) do
		if player and player.Character and player.Character.Parent then
			local humanoid = player.Character:FindFirstChild("Humanoid")
			if humanoid and humanoid.WalkSpeed < 16 then
				humanoid.WalkSpeed = 16
			end
		end
	end
	
	debris:AddItem(pickup,roundtime)
	pickup.Parent=game.Workspace
end

-- can change slashedplayer etc.
--tools
function newcharacter(slashedplayer, character)
	local humanoid = character:FindFirstChild("Humanoid")
	if humanoid then
		humanoid.Died:connect(function()
			end)
			if slashedplayer == detective then
				humanoid:UnequipTools()
				local backpack = slashedplayer:FindFirstChild("Backpack")
				if backpack then
					backpack:ClearAllChildren()
				end
			local torso =character:FindFirstChild("Torso")
			if torso then
				dropnetgun (torso.Position)
			end
			
			
			local tag = humanoid:FindFirstChild("Creator")
			if tag and tag.Value and tag.Value.Parent == game.Players then
			if tag.Value ~= slasher and slashedplayer ~= slasher then
				local wrongdoer = tag.Value
				if wrongdoer.Character and wrongdoer.Character.Parent then
					local wrongdoerhumanoid = wrongdoer.Character:FindFirstChild("Humanoid")
					if wrongdoerhumanoid then
						wrongdoerhumanoid.Health = 0
					end
				end
			end
			end
		end
			
	end
end
--leaderstats
function playeradded(player)
	local leaderstats = Instance.new("IntValue")
	leaderstats.Name = "leaderstats"
	
	local points = Instance.new("IntValue")
	points.Name = "Points"
	points.Parent = leaderstats
	
	leaderstats.Parent = player
	
	player.CharacterAdded:connect(function(character)
		newcharacter(player, character)
	end)
	if player.Character and player.Character.Parent then 
		newcharacter(player, player.character)
	end
end
game.Players.PlayerAdded:connect(playeradded)
for _, player in pairs(game.Players:GetPlayers()) do
	playeradded(player)
end


--loading in the map and bringing players to it.
while true do
	statustag.Value = "Loading Map"
	timertag.Value = -1
	mapholder:ClearAllChildren()
	wait(2)
	local allmaps = maps:GetChildren()
	local newmap = allmaps[math.random(1, #allmaps)]
	newmap.Parent = game.Workspace
	wait(2)
	
	
	while true do 
		wait (5)
		contestants = {}
		for _, player in pairs(game.Players:GetPlayers()) do
			if player and player.Character then
				local humanoid = player.Character:WaitForChild("Humanoid")
				if humanoid and humanoid.Health > 0 then
					table.insert(contestants, player)
				end
			end
		end
		-- how much players needed to play
		if #contestants >= 3 then
			break
		else
			--waits for players
			statustag.Value = "Waiting for Players"
			timertag.Value = -1
		end
	end
	
	
	--when the match starts
	statustag.Value = "Match"
	timertag.Value = roundtime
	
	
	slasher = contestants[math.random(1, #contestants)]
	
	--chooses whos who ( will need to remove or change up cause involves gui
	while true do
		randomplayer = contestants[math.random(1, #contestants)]
		if randomplayer ~= slasher then
			detective = randomplayer
			break
		end
	end
	
--telport contestants/players ro game and spawns them in the map properly, and when ends, teleports back to lobby
local spawnsmodel = newmap:WaitForChild("Spawns")	
local spawns = spawnsmodel:GetChildren()
for _, player in pairs (contestants) do
	if player and player.Character and #spawns > 0 then
		local torso = player.Character:WaitForChild("Humanoid")
		local humanoid =  player.Character:WaitForChild ()
		local spawnindex = math.random(1, #spawns) 
		local spawn = spawns[spawnindex]
		if spawn and torso and humanoid then
			humanoid.Health = 100
			humanoid.WalkSpeed = 16
			table.remove(spawns, spawnindex)
			torso.CFrame = CFrame.new(spawn.Position + Vector3.new(0, 3, 0))
			
			local matchtag = Instance.new("StringValue")
			matchtag.Name = "MatchTag"
			matchtag.Parent = player.Character
			--part of gui, may need to remove or change cause this is what gives the player the information of what they are
			local backpack = player:FindFirstChild("Backpack")
			if backpack then
				if player == bloxxer then 
					 local sword = serverstorage:WaitForChild("Sword"):clone()
					 sword.Parent = backpack
				elseif player == detective then
					event:FireAllClients("Class", "Slasher")
					local netgun = serverstorage:WaitForChild("NetGun"):clone()
					netgun.Parent = backpack
					event:FireAllClients("Class", "Detective")
				else
					event:FireAllClients("Class", "Citizen")
					end
				end
			end
		end
	end
	spawnsmodel:remove()
--above last line removes the person's role for that round, and clones it so it chooses a different one next round



--timer and a little bit of gui working
	local localtimer = roundtime
	while localtimer > 0 do
		wait(1)
		localtimer = localtimer - 1
		timertag.Value = localtimer
		
		activecontestants = {}
		slasheractive = false
		for _, players in pairs (contestants) do
			if player then
				local character = player.Character
				if character then
					local matchtag = character:FindFirstChild("MatchTag")	
					local humanoid = character:FindFirstChild("Humanoid")
					if matchtag and humanoid and humanoid.Health > 0 then
						if player == slasher then
							slasheractive = true
						end
						table.insert(activecontestants, player)
					end
				end
			end
		end
		if #activecontestants <=1 or not slasheractive then
			break
		end
	end


--game results
--slasher captured
--if the slasher won and is successful
--sorting the game results
	local gameresult = "PlayersWin"
	if slasheractive then
		if #contestants > 2 then
			--slasher failed
			event:FireAllClients("Result", "PlayersWin")
		else
			--slasher is successful
			gameresult = "SlasherWin"
			event:FireAllClients("Result", "SlasherWin")
		end
	else
		--slasher captured	
		event:FireAllClients("Result", "PlayersWin")
	end
	for _, v in pairs(game.Workspace:GetChildren()) do
		if v then
				if v.Name == "Pickup" or v.className == "Hat" then
					v:remove()
				end
			end
		end
	end
	for _, player in pairs(contestants) do
		if player then 
			if gameresult == "SlasherWin" and player == slasher then
				awardpoints (player, 9)
			elseif gameresult ~= "SlasherWin" and player ~= slasher then
				if player == detective then
					awardpoints(player, 4)
				else
					awardpoints(player, 2)
				end
			end
		end
	end
	
	
--teleports players to the lobby
	local lobbyspawns = {}
	for _, v in pairs(game.Workspace:WaitForChild("Lobby"):GetChildren()) do
		if v and v.Name == "SpawnLocation" then
	     	table.insert(lobbyspawns, v)
		end
	end
	for _, player in pairs(activecontestants) do
		if player then
			awardpoints (player, 1)
			if player.Character then
				local humanoid = player.Character:FindFirstChild("Humanoid")
				if humanoid then
					humanoid:UnequipTools()
				end
			end
			
			local randomspawn = lobbyspawns[math.random(1, #lobbyspawns)]
			player.Character:MoveTo(randomspawn.Position)
			local backpack = player:FindFirstChild("Backpack")
			
			if backpack then
				backpack:ClearAllChildren()
			end
		end
	end

	--intermission wait
	statustag.Value = "Intermission"
	timertag.Value = intermissiontime
	local localtimer = intermissiontime
	while localtimer > 0 do
		wait(1)
		localtimer = localtimer - 1
		timertag.Value = localtimer
		end





I think that the error is happening somewhere between line 10, and 30, yet I can't figure out how to fix it. Please help if you know anything on this.

1 comment

0

Infininte Yeild means that the WaitForChild() is stuck in an infininte loop of waiting for that thing to appear... To see if it's true that the RemoteEvent or the StatusTag are not appearing, go test the game and go to the explorer and go to the ReplicatedStorage and see if they're there. If they are not, it's because it can't find them. Also Infininte Yeild is not an error but a warning.

1 answer

###Infinite yields are not errors, they are warnings. Warnings are in yellow text, whilst errors are in red. The warning is there because of WaitForChild. It basically tells you that the script will yield indefinitely (and possibly break, it has happened to me) if the script waits too long for the specified child.

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