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

How to use setfenv to add custom requirements to global functions?

Asked by
ben0h555 417 Moderation Voter
6 years ago

I need to sandbox my scriptbuilder so the players can't disconnect players, I have found out how to insert custom values like so:

function code(string)
    -- I insert a custom FE converter before the loadstring here.
    loadstring(string)
end

setfenv(code, {
    Workspace = workspace,
    Game = game,
    -- The above 2 values are for deprecated global value support
    Require = nil,
    require = nil,
    -- I make the "require" value nil to prevent using 'require(num)' to get past my existing sandboxing.
    print = [function(text)
        game.ReplicatedStorage.PrintEvent:FireServer(tostring(text))
    end]
    -- The above function is to redirect the message to a custom GUI output
})

link2string = HttpService:GetAsync( URL )
-- Above fetches the pastebin string.
code(link2string)
--  Above activates the function with the included string.


-- NOTE: This is not my entire code, it is a basic overview.

However, I have no idea how to do the above on global functions like ":Destroy()" or ":FindFirstChild()"

Without that, I cant keep players from disconnecting other players using the global destroy function.

So you can see, I need to know how to edit or disable those global functions otherwise it would be chaos.

So thats where I ask for your help, I have searched around the web and found no clear answer to this question.

A clear, easy to understand answer would make my day.

0
Why dont you just run if str:find(":Destroy") then return end ? (And for all your other cases.) RubenKan 3615 — 6y
0
Because they can just do something like this, "Player:("Des".."troy")()" ben0h555 417 — 6y
0
string.find is basically the worst way to fix this problem, :/ ben0h555 417 — 6y
0
But "Des".."troy" will be "Destroy". User#19524 175 — 6y
0
Thats not how string.find works, incapaz. ben0h555 417 — 6y

Answer this question