Help with deleting inserted scripts

I’m making a script that deletes LocalScripts that haven’t been inserted into table SAFE_SCRIPTS.

Basically how it works is function transferLocalScripts goes through all of the instances in CLIENT_SIDED_SERVICES and check for all of the LocalScripts that are presnelty in them. It then inserts all of them into SAFE_SCRIPTS. These LocalScripts are now whitelisted, and are recognised as safe.

searchClientServices is called every 60 seconds in the while loop at the bottom. Every time it is called, it searches the instances in CLIENT_SIDED_SERVICES and checks for more LocalScripts. If there is a LocalScript, it then proceeds to run through SAFE_SCRIPTS and checks the name. If there is a LocalScript in CLIENT_SIDED_SERVICES and not in SAFE_SCRIPTS, it destroys it.

local CLIENT_SIDED_SERVICES = {
	game.Workspace,
	game["Run Service"],
	game.GuiService,
	game.Stats,
	game.SoundService,
	game.ReplicatedStorage,
	game.ReplicatedFirst,
	game.StarterGui,
	game.StarterPlayer,
	game.StarterPlayer.StarterCharacterScripts,
	game.StarterPlayer.StarterPlayerScripts
}

local SAFE_SCRIPTS = {}

local function transferLocalScripts()
	for index1, service in pairs(CLIENT_SIDED_SERVICES) do
		for index2, foundscript in pairs(service:GetDescendants()) do
			if foundscript:IsA("LocalScript") then
				table.insert(SAFE_SCRIPTS, foundscript)
			end
		end
	end
end

local function searchClientServices()
	for index1, service in pairs(CLIENT_SIDED_SERVICES) do
		for index2, insertedscript in pairs(service:GetDescendants()) do
			if insertedscript:IsA("LocalScript") and not SAFE_SCRIPTS[insertedscript] then
				insertedscript:Destroy()
			end
		end
	end
end

transferLocalScripts()

while wait(60) do
	searchClientServices()
end

How I’ve tested this on my own is by using the command bar to Instance.new a LocalScript into one of the instances listed in CLIENT_SIDED_SERVICES, waited 60 seconds and then it should have been deleted. But no, the LocalScript doesn’t get deleted, and I don’t see why. no errors are thrown, can anyone help me please?

You can’t access game.StarterPlayer from a script.

the script should be a local script so it can replicate changes from the client, because it will not replicate to server, or have a remote event

Yes and you can’t access StarterPlayer from a script because it’s content gets replicated to the player and the original service gets destroyed.

1 Like

Yes I’ve just realised what I’ve done, I can’t access client sided services from a script, and that’s what I’m trying to do.

Please check: StarterPlayer | Roblox Creator Documentation

You can find the contents of the StarterPlayerScripts in the player and character in the character. Fire the client if you want to use a serverscript for this operation.

If this is a method to fight exploiters, it won’t work. Every player has total control over their LocalScripts. Even if you make a LocalScript that delete other LocalScripts, player can delete that himself

1 Like

Detection of deleting a clientside script is possible with a serverside script. However if this is a method to fight exploiters, it is a bad one.