How To Remove All Scripts In A Game

So, my friend made an awesome game but the thing is, he used lots of free models and it has a lot of viruses. I was wondering if there’s a script out there that can delete all scripts in a game?

I tried use for i,v in pairs() and got the game’s descendants but I do not have the permissions I need. (I’m not sure how to use PCalls)

Please help!

4 Likes

Just type the word “script” in the explorer search bar and then delete every script you don’t recognise.
This should get rid of any malicious code.
Hope that helped,
Theyoloman1920

1 Like

That doesn’t really help. Sorry. There are wayyy too many scripts to do that and there’s a more simplier way using PCalls and for i,v in pairs. Sorry.

I’m not sure how to use PCalls though :confused:

1 Like

You’d be better off typing “script” in the explorer search and combing through each script to ensure its meant to be there.

If you still want to proceed with deleting all scripts in the game though you can use this in the command bar:

for i,v in pairs(game:GetDescendants()) do
	if v:IsA("Script") or v:IsA("LocalScript") or v:IsA("ModuleScript") then
		v:Destroy()
	end
	if i%25 == 0 then
		wait()
	end
end
7 Likes

For some reason it didn’t work. No output.

Edit: Nvm it just takes a while.

3 Likes
pcall(function()
	for i,v in pairs(game:GetDescendants()) do
		if v:IsA("Script") or v:IsA("LocalScript") or v:IsA("ModuleScript") then
			v:Destroy()
		end
		if i%25 == 0 then
			wait()
		end
	end
end)
2 Likes

Sorry, it actually did not work for some reason :confused:

Guess you can’t use the :GetDescendants() method on game because of a permission issue.

Try this instead:

local services = {"workspace", "ReplicatedFirst", "ReplicatedStorage", "ServerScriptService", "ServerStorage", "StarterGui", "StarterPack", "StarterPlayer", "Teams"}
for _,service in pairs(services) do
	if game[service] then
		for i,v in pairs(game[service]:GetDescendants()) do
			if v:IsA("Script") or v:IsA("LocalScript") or v:IsA("ModuleScript") then
				v:Destroy()
			end
			if i%100 == 0 then
				wait()
			end
		end
	end
end
13 Likes

This is a good solution! : D LOL

Amazing solution, helps a lot with really bad scripts.

( Ugly but useful Necro )

if you add (game.Workspace.[Parent].[Child (if any and so on)]:GetDescendants to this, you pick a specific piece of structure to delete, really helpful when scripts have 100s of them but your game also has scripts you wish to save.

Edit: Wrong reply, oops. Still links to the original solution.

1 Like

This is an old thread but hey, all the above solutions are over-complicated.

for i, v in pairs(game:GetDescendants()) do
	if v:IsA("Script") or v:IsA("LocalScript") or v:IsA("ModuleScript") then
		pcall(function()
			v:Destroy()
		end)
	end
end

Simple, effective. No need to wait or write out certain services.

(oops accidental reply)

1 Like

Run this in the Command Bar in Roblox Studio

for _,v in pairs(game:GetDescendants()) do pcall(function() if v:IsA(“Script”) or v:IsA(“LocalScript”) or v:IsA(“ModuleScript”) then v:Destroy() end end) end
2 Likes