Script Counter Issues

Hey Developers!, I’m trying to make my first “Script Counter”, But, while i run into the loop,
I Get this error, Is there any way to avoid this?, i guess I Don’t have permission to check the ClassName of certain objects? this error breaks the loop, making me unable to use it

Error:
Screenshot_3578

Script:

--Script Counter
local Delay = .0005

function CountScripts()
	local Final_Scripts =0
	local Final_LocalScripts =0
	local Final_Modules =0
for _,child in pairs(game:GetDescendants()) do
	if child:IsA("Script") then
		Final_Scripts = Final_Scripts + 1
	elseif child:IsA("LocalScript") then
		Final_LocalScripts = Final_LocalScripts + 1
	elseif child:IsA("ModuleScript") then
		Final_Modules = Final_Modules + 1
	end
	yield(Delay)
end
	warn("Done")
	ScriptCounter_Scripts.Text = "Server Scripts: "..Final_Scripts
	ScriptCounter_LocalScripts.Text = "Local Scripts: "..Final_LocalScripts
	ScriptCounter_Modules.Text = "Modules : "..Final_Modules
end

Feel free to give any tips to improve it aswell.

Some services under the DataModel Instance aren’t available to be used within scripts and throw an error when indexed, best solution would be to pcall the for loop scope.

ie.

for _, Child in ipairs(game:GetDescendants()) do 
    pcall(function()
        --// Code
    end)
end
3 Likes

Alright. That looks like the solution I’m looking for, ill give it a try, and mark your comment as the solution, tysm!

Edit: All Good!, Thanks again!

1 Like

I’m pretty sure Script covers both normal and local scripts, but not module scripts. That’s what it does for me anyway.

Also, isn’t there a plugin for this?

I like to make my own stuff, but thanks for the information. I actually didn’t know that