The current identity (5) cannot Class security check (lacking permission 6) - For a CD command?

Hello, DevForum!

I’ve been trying to make a cd command for a plugin that acts like a console for roblox studio, just one problem. Every time I run cd StarterGui or cd .. the script spams this error and almost crashes my studio.

  07:55:45.146  The current identity (5) cannot Class security check (lacking permission 6)  -  Studio - cd:47
  07:55:45.147  Stack Begin  -  Studio
  07:55:45.147  Script 'user_lua.console.rbxmx.lua.console.PluginManager.Commands.cd', Line 47 - function changeDir  -  Studio - cd:47
  07:55:45.147  Script 'user_lua.console.rbxmx.lua.console.PluginManager.Commands.cd', Line 107  -  Studio - cd:107
  07:55:45.147  Script 'user_lua.console.rbxmx.lua.console.PluginManager', Line 97  -  Studio - PluginManager:97
  07:55:45.147  Stack End  -  Studio

I am not really getting what it means. I am able to do cd Workspace and have it work, but other than that, everything else gives me this error. I don’t know what I am doing wrong and I have tried this post, but even after wrapping stuff in pcalls it kept giving this error.

Main Function Inside Module Script

--|| VARS ||--
local command = {}
local currentDir = game

--|| FUNCTIONS ||--
local function printDir()
	local children = currentDir:GetChildren()

	for i = 1, #children do
		local ok, service = pcall(function()
			return children[i]
		end)

		if ok then 
			print(children[i].Name)
		end
	end
	
end
local function changeDir(input, consoleUI)
	if input == ".." then
		if currentDir == game then
			local newResponse = script.Parent.Assets:WaitForChild("Response"):Clone()

			if consoleUI.Assets:FindFirstChild("Response") then
				consoleUI.Assets.Response.Name = "OldResponse"
			end

			newResponse.Parent = consoleUI.Assets

			newResponse.TextColor3 = Color3.new(0.929992, 0.718502, 0.698558)

			newResponse.Name = "Response"
			newResponse.Text = "ERR: cannot go above the game root"

			return

		else
			currentDir = game
			printDir()
			return
		end
	end
	local foundChildDir = nil
	
	for _,v in pairs(currentDir:GetChildren()) do
		if string.match(v.Name, input) then -- Line 47, main problem here I guess
			foundChildDir = v
			break
		end
	end
	
	if foundChildDir ~= nil then
		currentDir = foundChildDir
		printDir()
		return
	end
	
	local newResponse = script.Parent.Assets:WaitForChild("Response"):Clone()

	if consoleUI.Assets:FindFirstChild("Response") then
		consoleUI.Assets.Response.Name = "OldResponse"
	end

	newResponse.Parent = consoleUI.Assets

	newResponse.TextColor3 = Color3.new(0.929992, 0.718502, 0.698558)

	newResponse.Name = "Response"
	newResponse.Text = "ERR: no such directory"

	return
end

-- Down here is the command handler but that isn't important for this.

If anyone could help that’d be greatly appreciated :smiley:

The console is telling you the error. It’s unable to Class security check it because it has no permissions.

Well yeah but um, what does that mean and where can I fix it?

The loop attempts to access children in the DataModel class that are core-script exclusive.

I don’t think you can wrap permission errors in an error catcher (correct me if i’m wrong)
Thank you @Aegians for correcting me

Why are you using this useless loop? You are aware that FindFirstChild exists, correct?

for _,v in pairs(currentDir:GetChildren()) do
	if string.match(v.Name, input) then -- Line 47, main problem here I guess
		foundChildDir = v
		break
	end
end
1 Like

You can catch permission errors with a protected call, I’ve done it before.

1 Like

Yes but then how could I set foundChildDir to a Instance not the string Input

if currentDir:FindFirstChild(input) then
   foundChildDir = input -- Would be a string, not an instance
end

Probably missing something, but I am not sure how

Ok, the problem is when looping with GetChildren() I don’t think I can exclude these Core-Script exclusives. Is there a way to ignore these?

Try this:

local ok, service = pcall(function()
	return children[i]
end)

if ok then 
	print(service.Name)
end

Screen Shot 2021-02-26 at 8.55.46 AM

Tried but got the error on the

if ok then 
	print(service.Name) -- Error Here
end

Ok, my other solution would be to return the service’s name

local ok, service = pcall(function()
    return service.Name -- the protected call should catch this error
end)

if ok then
   print(service)
end

Screen Shot 2021-02-26 at 8.59.38 AM

Hmmm, service is right there in the pcall though…

Made a mistake, replace it with this:

return children[i].Name

the service variable doesn’t exist inside the pcall

1 Like

Screen Shot 2021-02-26 at 9.03.02 AM

Woahhhh, just cd’d into the game root and got this. Don’t see any errors so I will keep testing.

Ok cool, so I can’t CD into StarterGui or StarterPlayer, other wise it gives the same error on line 47.

Is there a way to catch this error? So if the player tries to cd into one of these areas where it can’t go, it’ll just stop it and return a message?

	for _,v in pairs(currentDir:GetChildren()) do
		if string.match(v.Name, input) then -- Line 47, main problem here I guess
			foundChildDir = v
			break
		end
	end

Sorry, not good with this kinda stuff, only know it from .catch() in JS.

Not exactly sure, you may have to make a table with a list of classes that the cd shouldn’t try to access

local excluded = { game.StarterPlayer , game.StarterGui }

Or you can use the pcall and try to see if the service variable is equal to the object’s name

Hm, I think you can sadly only cd into workspace and it’s descendants, so how could I just exclude everything except workspace?

You could try to see if whatever the cd is trying to access, is not workspace

if currentDir ~= workspace then
   return -- stops the function or whatever it's in
end

-- do something like this
if currentDir:FindFirstChild(input) then
  foundChildDir = currentdir:FindFirstChild(input) -- Would be a instance, not an string
end

It’s surprising how many developers don’t know the basic behavior of Instance functions. It takes a glance at the developer hub to see what each function returns.