Can I detect a script error?

image
Still does not work after one second

This works when the script is running, but we need something that works while in studio.

Try parenting the plugin to an Actor.

1 Like

I have never done that (as I said I’m new to plugins), how do I do it?

Just parent them to an Actor model instead of a folder. This will start them in parallel.

1 Like

I didn’t get any output this time.

Looks like the plugin didn’t load at all. Probably just another studio issue.

I actually have never tried parenting anything to a plugin script before, so this is new to me. Try restarting studio and enabling plugin debugging.

1 Like

Still no error or anything, not sure how to enable plugin errors.

I wish i could help this topic more but i do not know Enough about scripting.

It’s not that. I actually have no idea what could possibly be causing this, I’m curious myself.

1 Like

Anything wrong with the script?


task.wait(1)
local Load = require(script.StringLoader)
local SES = game:GetService("ScriptEditorService")
local toolbar = plugin:CreateToolbar("Nerd Script Helper")
local NewButton = toolbar:CreateButton("🤓", "owo", "http://www.roblox.com/asset/?id=10218508810")
NewButton.Click:Connect(function()
	for i, v in ipairs(game:GetDescendants()) do
		if v:IsA("Script") or v:IsA("LocalScript") then
			v:GetPropertyChangedSignal("Source"):Connect(function()
				local succ, err = pcall(function()
					Load(v.Source)
				end)
				if not succ then warn(err) end
			end)
		end
	end
end)
1 Like

You should be using pairs instead of ipairs. I also think that you should disconnect the connections after it is clicked again to prevent memory leaks.

1 Like

Smart idea i will bookmark this to remember if i make a plugin

Now why is it not working?


task.wait(1)
local Load = require(script.StringLoader)
local SES = game:GetService("ScriptEditorService")
local toolbar = plugin:CreateToolbar("Nerd Script Helper")
local NewButton = toolbar:CreateButton("🤓", "owo", "http://www.roblox.com/asset/?id=10218508810")
local db = true
local conn 
NewButton.Click:Connect(function()
	if db == true then
		db=false
		conn = function()
			for i, v in pairs(game:GetDescendants()) do
			if v:IsA("Script") or v:IsA("LocalScript") then
				v:GetPropertyChangedSignal("Source"):Connect(function()
					local succ, err = pcall(function()
						Load(v.Source)
					end)
					if not succ then warn(err) end
				end)
			end
			end
		end
		conn()
	else
		db = true
		conn = nil
	end
end)

I don’t really know. I’d try doing GetDescendants as soon as the script starts and after the variables are assigned for testing.

So I looked through several documents and wasn’t able to find anything about an actual script error from the editor, however there is an instance called ScriptDocument which represents the open script editor. Thinking you could use this with loadstring, loadstring the script’s source (retrieved from GetLineCount() + GetLine()'ing each line concatenated with \n as a separator), then examine the error message and see what the error is.

You don’t have to pcall loadstring as it returns nil and the error message as the second argument if the source wasn’t loaded properly. So, doing loadstring(‘a’) returns nil, “[string “a”]:1: Incomplete statement: expected assignment or a function call” as a string, not an error message. If you want errors from the script’s source (eg. attempt to index nil with _, attempt _ is not a valid member of _, etc…), you can pcall the function returned from loadstring.

So,

local func, errorMessage = loadstring(someString)
if func then
    local success, result = pcall(func)
    if success then
        -- script was run successfully
    end
else
    -- script has some error that prevents it from being compiled
end

However do be aware that this can become CPU intensive and likely will cause a memory leak if you don’t structure your code in a certain way (returning connections from the function that loadstring returns/not using a module), or unless you are very good at sandboxing as the connections aren’t able to be managed externally afaik (no way to get a table of connected connections without another module), so do be conscious of that.

You can get a ScriptDocument that represents the currently open script editor from the ScriptEditorService:

3 Likes