Why I undo broken in my plugin?

Hey devforum, I have made a script which deletes scripts inside an object, but when I try to undo I get this error:

image

This is the plugin script:

local ChangeHistory = game:GetService("ChangeHistoryService")

local toolbar = plugin:CreateToolbar("DeleteScriptsInsideObject")
local button = toolbar:CreateButton("456342", "Plugin", "rbxassetid://4483361337", "DeleteScripts")

local selected

local amountOfObjectsSelected = 0

button.Click:Connect(function()
	selected = game.Selection:Get()
	for _, v in pairs(selected) do
		amountOfObjectsSelected = amountOfObjectsSelected + 1
		ChangeHistory:SetWaypoint("Idk")
		print("AddedWaypoint")
	end
	for i = 1 ,amountOfObjectsSelected, 1 do
		for _, v in pairs(selected[i]:GetDescendants()) do
			if v.ClassName == "LocalScript" or v.ClassName == "Script" or v.ClassName == "ModuleScript" then
				print("Script Deleted")
				v.Parent = nil
			end
		end
	end
	amountOfObjectsSelected = 0
end)






Unlock the parent instance of Main and try again.

But how do i unlock the parent, main is destroyed by :Destroy()

Even if you try to save the instance with ChangeHistoryService if you delete the scripts you can’t get it back. You should use :Remove() instead

2 Likes

It still doesn’t work, and when I save the plugin locally, this prints

But when I save it to roblox that doesn’t even print.

You probably didn’t select anything in the explorer.

This will work better

button.Click:Connect(function()
	selected = game.Selection:Get()
	for _, v in pairs(selected) do
		for index, object in pairs(v:GetChildren()) do
          if object:IsA("Script") or object:IsA("LocalScript") or object:IsA("ModuleScript") then
             object:Remove() --if you use remove you can get the object back if you press CTRL + Z
               print("Removed")
          end
        end
	end
         game:GetService("ChangeHistoryService"):SetWaypoint("blah")
end)

image

I don’t think you can change the parent of SoundService since it is a service itself.

1 Like

Then how do I remove the object being able to get it back later?

Oops I made a error in my script that’s why. I fixed it. I accidentally did this

v:Remove()

I changed it

object:Remove()
1 Like

Did you select anything in a explorer with a script in it? It only prints if you have selected something with a script inside it.

1 Like

Nvm figured it out, I was forgetting to update the plugin :sweat_smile:

1 Like