'Error occured, no output from Lua' error

I was iterating through game:GetDescendants() and was trying to compare each descendant’s ClassName with a string.

I’m making a ‘disinfectant’ script for some friends.

But, every time I ran it in a test mode or real server, I got the following error on the line doing the comparison.

Error occured, no output from Lua

This error only seems to happen when I’m using values from an array - AKA making it able to ‘softcode’.
I tried doing it with a hardcoded comparison, and it did not throw the error.

Here’s my code:

local ClassesToRemove = {"RotateP"}
local NamesToRemove = {"Vaccine"}

local function IsInfection(Object)
	for _,Class in pairs (ClassesToRemove) do
		if Object.ClassName == Class then -->> Errors here
			return true
		end
	end
	for _,Name in pairs (NamesToRemove) do
		if Object.Name == Name then
			return true
		end
	end
	return false
end

for _,Descendant in pairs (game:GetDescendants()) do
	if IsInfection(Descendant) then
		Descendant:Destroy()
	end
end

Any idea why this might be happening?

Thanks :wink:

The problem here is that you can’t call GetDescendants() on the game object, because some of its descendants are structured differently than a normal object. Try individually searching Workspace, Lighting, etc. and you should be fine.

3 Likes

This happens when you attempt to index a RobloxLocked object, there are some descendants of game that are RobloxLocked. RobloxLocked prevents you from indexing and manipulating in any way whatever object has been locked.

To fix this, wrap everything after the for statement in a pcall.

6 Likes

@Polymorphic @ChipioIndustries

Alright, thanks!

2 Likes

You need to pcall() wrap your index lines to allow for RobloxLocked items. pcall allows you to deal with errors without suspending the script.

For example - here’s an extract from a plugin I made at one point.

formatWorkspace = function()
	local descendants = workspace:GetDescendants()
	for _, descendant in pairs(descendants) do
		local pass = false
		pcall(function()
			pass = descendant:IsA("BasePart") 
		end) 
		if pass then
            print("is a part")
		end
	end
end