Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Is there a way to make / edit / read a script using another?

Asked by 6 years ago
Edited 6 years ago

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.

2 answers

Log in to vote
1
Answered by 6 years ago

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!

0
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! <PATH OF SUSPICIOUS SCRIPT>." ~ CrazyAceGaming0130 32 — 6y
0
~ (max limit reached) How can that be possible? CrazyAceGaming0130 32 — 6y
0
You can't scan a script for a virus code using another script. GIassWindows 141 — 6y
0
Well, I guess it's impossible. Thanks anyways. CrazyAceGaming0130 32 — 6y
Ad
Log in to vote
0
Answered by
EB8699 30
6 years ago

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.

0
I posted something from an earlier answer. Well, thanks for answering but it's not what I'm looking for. CrazyAceGaming0130 32 — 6y
0
Alright, fair enough. EB8699 30 — 6y

Answer this question