I’m making a script that deletes LocalScript
s 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?