How to create and write to a file in my local disk?

I need to debug my game, but as I used teleport I can’t debug it inside Studio.
So I have to resort to this terrible and limited Console Output Log from Roblox Player.
As I have a lot of multilevel tables, it’s very difficult to find something inside the console.
So I thought of copying the contents from the console to the clipboard.
But that is also not possible.
So I thought of LogService:GetLogHistory to get everything there and save it to a local file so I can search the result inside a text editor.
But I don’t see how to save this result to a local file.
Could anyone tell me how to do this?

I might be wrong or misguided but isn’t this not possible for security and sandboxing reasons?

The only way to do this is with plugins.
If i remember correctly, Plugin:PromptSaveSelection

Insert a script, force select it, call this function with the argument of “log.lua”, and there you go.

Unfortunately theres no txt file exportinf, try lua.

Quick function.

local function saveLog(name,str)
   local script = Instance.new("Script")
   script.Source = str
   script.Parent = workspace
   game.Selection:Set({script})
   return plugin:PromptSaveSelection(name)
end

--plugin
local button = plugin:CreateToolbar("Save output as log.lua"):CreateButton("Save","Saves the output as log.lua","")
button.Click:Connect(function()
   saveLog("log.lua",game.HttpService:JSONEncode(game.LogService:GetLogHistory()))
end)

Please mark as solution if it hwlped

edit : did lots of edit and im unsure if it works, but it should give you an idea to do this.

1 Like

You can save it to DataStoreService, then read it in studio (there’s a game setting to allow studio access.) Or you can copy it out of a text box.

3 Likes

Thanks, but when I run this, I get:

Workspace.Script:10: attempt to index nil with ‘CreateToolbar’
Stack Begin
Script ‘Workspace.Script’, Line 10
Stack End

Nono, save it as plugin, dont run it as a normal script.

Oh, sure.
It’s creating a file.
However, it’s also creating a local script every time I call the plugin:

Ah, let me edit this code real quick.

local function saveLog(name,str)
   local script = Instance.new("Script")
   script.Source = str
   script.Parent = workspace
   game.Selection:Set({script})
   local res = plugin:PromptSaveSelection(name)
   script:Destroy()
   return res
end

--plugin
local button = plugin:CreateToolbar("Save output as log.lua"):CreateButton("Save","Saves the output as log.lua","")
button.Click:Connect(function()
   saveLog("log.lua",table.concat(game.LogService:GetLogHistory()))
end)

enjoy

user_log.lua.Script:14: invalid value (table) at index 1 in table for ‘concat’
Stack Begin
Script ‘user_log.lua.Script’, Line 14
Stack End

Please give me a moment.

local function saveLog(name,str)
   local script = Instance.new("Script")
   script.Source = str
   script.Parent = workspace
   game.Selection:Set({script})
   local res = plugin:PromptSaveSelection(name)
   script:Destroy()
   return res
end

local function strfromtable(tbl)
   local ret = {}
   for _,v in pairs(tbl) do
      table.insert(ret,v.message)
   end
   return table.concat(ret)
end

--plugin
local button = plugin:CreateToolbar("Save output as log.lua"):CreateButton("Save","Saves the output as log.lua","")
button.Click:Connect(function()
   saveLog("log.lua",strfromtable(game.LogService:GetLogHistory()))
end)
2 Likes

It seems to be working now, thanks.
Although it still generates a script in the workspace, you are deleting it after.
So print ('123') in the console output will generate a lua.lua` file:

Thank you. :grinning:

2 Likes