Why am I getting this error?

Hi so I am getting this error "The current identity (2) cannot Class security check (lacking permission 1) "

Now I know this is an error you get when a script usually doesn’t have the permission on check something like core gui for example but that is not what I am doing here is my script:

game.DescendantAdded:Connect(function(descendant)
	if descendant:IsA("ScreenGui") then -- this is the line thats erroring

I don’t understand what I don’t have permission to do? Please let me know, thanks.

1 Like

Going off of this ScriptingHelpers post I think you need to destroy the ScreenGui via a local script rather than a server script

1 Like

This is probably because you’re using a method on a locked object (such as one in CoreGui). DescendantAdded will still fire for locked objects although you can’t access them

1 Like

Im not using it on core gui Im just using it on game.DescendantAdded:Connect(function(descendant) so the game, but thats not what errors it’s cheking ifs a gui that errors

CoreGui is a descendant of game

1 Like

Print the name of the descendant first, I think you are trying to use Isa on a service. Don’t know why that wouldn’t work though.

1 Like

It is a local script already, I don’t know why it’s erroring.

what do you mean? How would I write that?

game.DescendantAdded:Connect(function(descendant) 
if descendant.name == "Name" then --procced what to do.

like this?
I might as well just use FindFirstAncestor or something or can I use

game.DescendantAdded:Connect(function(descendant) 
if descendant.ClassName == "ScreenGui" then --procced what to do.

game.DescendantAdded will fire for all objects added anywhere to the game, CoreGui, workspace, Players, etc… What’s your use case? There’s most likely a better solution to what you’re trying to do

No just print it so you can see exactly what is causing it

I want it to fire for plr gui and core gui but if I say
game.CoreGui then it will stop working right off the bat so I want to be able for it to fire for core gui and player gui, I did access core gui the same way before I don’t know why it won’t work now.

you are trying to access the coregui thats why

Roblox doesn’t want developers to be able to access the coregui so they always patch all kinds of methods that people come up with. IIRC, you used to be able to tostring() the instances added to CoreGui before to see their names but they made it so any kind of access to coregui elements throws that error

2 Likes