I want to run some code in the command bar to disable ALL scripts. That means modulescripts,locals,scripts.
But using:
for i,v in pairs(game:GetDescendants()) do if v:IsA("Script") then v.Disabled = true end end
runs into some Terrain.Locked kinda stuff:
The permissions are not granted. So I need help making a script that does what I want without getting shot down by some authority fail safe like this.
3 Likes
You can wrap the if
statment inside a pcall
(protected call, essentially catches errors) to stop the code from erroring.
For example:
for i,v in pairs(game:GetDescendants()) do
pcall(function()
if v:IsA("Script") then
v.Disabled = true
end
end)
end
The errors shown will happen because you’re trying to read / write to a service or instance that is locked to higher privileges only.
2 Likes
I found out that using ScriptContext.ScriptsDisabled
ScriptContext | Documentation - Roblox Creator Hub is the correct implement to use with the command bar when using studio.
Your code is good at what it does. But do you happen to know how to properly check script security levels? Or is pcall really just the way to go?
BoKVictor
(Birdie)
#4
Thanks I really liked this answer!!!