Permissions error

Hello! Today I’m trying to make a system that has the scope to check if a localscript inside the game gets destroyed and if yes clone it and put it back

for i, v in pairs(game:GetDescendants()) do
	if v:IsA("LocalScript") then

if v:IsA(“LocalScript”) then

At this line I get this error: The current identity (2) cannot Class security check (lacking permission 6)

Is there a way to do this or it is reserved just to roblox?

Basically I was creating an anti dex system, like when exploiters delete a localscript which has the function of an antiexploit

I would recommend only checking places where local scripts operate. Checking the whole game is unneeded. The error you are getting is telling you that you are checking something that you don’t have access to.

p.s. use ipairs

Look at this:

If not even the creator or plugins can access, much less an exploiter.

Some descendants of the game are unable to read/check because they’re locked for use by Roblox only, meaning nothing else is allowed to access them, hence the error

For what you are doing, I’m not sure, maybe you can do a pcall as the post by @SOTR654 suggested so it only goes through accessable services for checking if a localscript gets destroyed?

local descendants = game:GetDescendants()

while true do
	for i = 1, #descendants do
		local success, errormessage = pcall(function()
			return descendants[i]

		if success then -- Proceed with scanning service
			if descendants[i]:IsA("LocalScript") then

@EmbatTheHybrid It isn’t working, is something wrong?

Since my game has a lot of LocalScript I should add this check to every LocalScript, I may forget one of them and that could be a problem, I would also use this for every LocalScript inside the game and not just the ones which are anti exploit components.

Why do you need to check this in the first place?
This will lag a lot, especially if a localscript is removed too often.

Because as you may know everything that isn’t on the server side can be manipulated by exploiters and i want to do this so it checks everything inside the game and if something gets destroyed it will ripristinate it.

They can easily disable / remove your script as they have access to everything on their computer.
All you’re causing is lag for other players if anything.

No because that script is a server script located in ServerScriptService which cannot be accessed by exploiters

Server-sided scripts cannot detect if a client removes or add a localscript.
You should find another solution.

That change is not replicated to the server.

Uhm really i don’t know if the exploits edits only the client, i’m not interested if they broke the client, i’m interested just to prevent things that can happen for every player.

Elaborate, I don’t understand what you mean by “things that can happen for every player”.
Exploiters do not have access to the server or any server-sided scripts.

What you might refer to is an issue called client-server replication, such as their character’s position.

I will try to be clear. I want a script that checks if an exploiter with a dex destroy script inside of other player in the Players section or if they modify others’ gui ecc, it is based on ChildRemoved so if something gets removed it will remake it

That is not possible, the changes won’t replicate to the server.

for i, v in pairs(game:GetDescendants()) do
local success, result = pcall(function()
return v and v:IsA('LocalScript')

if success and result then
--[[ insert code here ]]

Also I’m guessing that your making an anti exploit system, if you are this would probably not work since the exploiter’s changes only replicate to the client’s screen.

Do you mean exploiter’s action or my script actions?

The server won’t be able to pick up that change because they are implementing the changes on their client only.

That is a problem too since if i insert localscripts as anti exploit components in their character they can remove them and bypass them.

They can do that, yes. However the majority of exploiters doesn’t have a clue on what they’re doing.
You can implement a client-sided anticheat, but it won’t protect your game against the ones who know what they’re doing.