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

Infinity yield possible how to solve this?

Hello guys i have a script for tool removing but i get this error on output

local player = game:GetService("Players")
local backpack = player:WaitForChild("Backpack")
local removableLaunchers = {"SledgeHammer"}

local function purgeLaunchers(container)
	for _, launcher in pairs(removableLaunchers) do
		local tool = container:FindFirstChild(launcher)
		if tool and tool:IsA("Tool") then
			tool:Destroy()
		end
	end
end

purgeLaunchers(backpack)
purgeLaunchers(player)

local backpack = player:WaitForChild("Backpack") for second line the outputs says infinity yield possible how to solve this?

1 answer

So we meet again TheMostDelikanliMan!

Your issue here is simple!

local player = game:GetService("Players")

You defined "player" as the games PlayerService itself!

Backpack is a child of the player object! Therefore, you need to do what is listed below.

local player = game:GetService('Players').LocalPlayer

For future reference, you get the Infinite Yield error if the child is not present. You need to make sure that the object/item you're putting inside of the :WaitForChild('') is inside of the parent.

4 comments

0

If this works be sure to mark it as the answer!

0

infinite yield problem is solved but it says stack end at line 2, so script is not working

0

Alright, let me review. Could you post the new script? And is this a local script or server script? Also, don't do :WaitForChild('Backpack'). Just do player.Backpack

0

you couuld do player:FindFirstChild("Backpack")

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