So I was having trouble with my evaluator and global variables, and since I didn't want to rewrite every variable, I added {__index = _G } after my setfenv
my current code looks like this
script.Parent.MouseButton1Click:Connect(function()
local eval = script.Parent.Parent.Input.Text
local output = ''
local environment = setmetatable({
-------------------------------------------
hs = game:GetService("HttpService"),
-------------------------------------------
print = function(...)
local args = {...}
for i = 1, select('#', ...) do
args[i] = tostring(args[i])
end
output = output .. table.concat(args, '\t')
end
-------------------------------------------
},{__index = _G} )
local func, err = loadstring(eval)
if func then
setfenv(func, environment){__index = _G}
local ok, ret = pcall(func)
if ret ~= nil then
output = tostring(ret) .. '\n'
end
else
output = err
end
script.Parent.Parent.Output.Text = output
end)
When doing something like printing Hello World!, it prints
Hello World!Hello World!
and I have no idea why. It did not do this before I added global variables, and I think It has something to do with me having the print function in my meta table, but I don't know.
