I have lived with this problem for a while, but I think it's finally time to fix it. Studio keeps crashing on this script:
local ScriptContext = game:GetService("ScriptContext")
local PluginMouse = plugin:GetMouse()
Alert = script.Alert -- Bug fix attempt
FirstTime = true -- Bug fix attempt
ScriptContext.Error:Connect(function(message, stackTrace, scriptinstance) -- Runs when an error happens
if FirstTime == false then -- Bug fix attempt
local alert = Alert:Clone()
local line1 = " "..tostring(scriptinstance.Name)..", "..tostring(string.gsub(stackTrace, scriptinstance:GetFullName()..", ", "")) -- Script instance and line number (where error occured)
local replacement = scriptinstance:GetFullName()..":"..string.gsub(stackTrace, scriptinstance:GetFullName()..", line ", "") -- The second argument in string.gsub: the script instance found in an error message
local replacement2 = string.gsub(replacement, "\.", "\.")
local preline2 = " '"..string.gsub(message, replacement2, "").."'"
local line2 = string.gsub(preline2, "' ", "'") -- The string.gsub that removes script instance from error message
alert.Location.Text = line1 -- Script instance and line number
alert.ErrorMessage.Text = line2 -- Error message by itself
local linenumber = tonumber(tostring(string.gsub(string.gsub(stackTrace, scriptinstance:GetFullName()..", line ", ""), " ", ""))) -- Line number by itself
alert.Location.LineNumber.Value = linenumber -- For plugin:OpenScript on script that is getting cloned (easy access to where error occured)
alert.Location.ScriptInstance.Value = scriptinstance -- Also for plugin:OpenScript
alert.Parent = script.Parent -- From here is the part where the error appears and sound is played
local ErrorSound = Instance.new("Sound")
ErrorSound.SoundId = "rbxassetid://5188022160"
ErrorSound.PlayOnRemove = true
ErrorSound.Parent = game.Workspace
ErrorSound:Destroy()
local script1 = require(alert.MovementScript)
local script2 = require(alert.Location.ShortcutScript)
local script3 = require(alert.DestroyScript)
alert:Destroy() -- Error has disappeared and will now be deleted
end
end)
FirstTime = false -- Bug fix attempt
This is part of an error alert system for my plugin. This script is in control of cloning and running all the scripts that are inside the clone. The system works fine.
Anyways, the error is:
14:45:34.627 - CoreGui.DevHelper 2.Script:8: attempt to index nil with 'Name'
And of course:
14:45:34.626 - Maximum event re-entrancy depth exceeded for ScriptContext.Error
What is happening and how do I fix it?

1 comment
Your script is formatted terribly bad