I want to make something for my model. I want to add an "anti-virus" thing so if I tried a script, which is a virus, it'll scan the code and tell if it's safe or not before running it. But my problem was the scanning itself. Is there a way to make scripts read scripts? If yes, how does one achieve it? Thanks.
Is there a way to make / edit / read a script using another?
2 answers
You can't edit a script using another script. However, you can use it's functions if you add _G.
For example:
_G.name = function()
print("Soup time")
end
Using another script, you can call the function by doing:
_G.name()
Hope this helps!
Sorry mate, but you can't edit other scripts sadly.
What you Can do however is destroy scripts that are inserted after the game runs. It's not a full-proof way to do it but it's about as close as you can get.
local Model = script.Parent
local Whitelist = {}
--Configs--
local AllowBase = false --Toggle true to allow scripts that are present when game starts
--End configs--
for i, v in pairs(Model:GetDescendants()) do
if v:IsA("BaseScript") and AllowBase == false then
v.Disabled = true
v:Destroy()
end
end
Model.DescendantAdded:connect(function(instance)
if instance:IsA("BaseScript") then
v.Disabled = true
v:Destroy()
end
end)
Generally speaking you shouldn't be inserting scripts into the workspace after the game is running anyway. More secure that way.
There is a more complicated way to do it, but by that point it's probably just easier to go with the "MainScript" in ServerScriptService rather than whitelisting certain scripts.
2 comments
I posted something from an earlier answer. Well, thanks for answering but it's not what I'm looking for.
Alright, fair enough.
This discussion is preserved as it was. New answers, comments, and votes are closed.

4 comments
Thanks for the answer, but I wasn't looking for using a function from a script using another one. Let me make it clearer. I want to make a script that notices me of a part of a code in another script. For example, if the script, let's call it Anti-virus, finds a part of code in a separate script (such as ITEM:Destroy()), it will print this: "A script is suspicious! ." ~
~ (max limit reached) How can that be possible?
You can't scan a script for a virus code using another script.
Well, I guess it's impossible. Thanks anyways.