Hey devforum, I need some help with this plugin script. I just started larning how to make a plugin and I am making one for practice. The plugin I am making should delete all scripts inside the object you select and its descendants. It works well, but when I try to undo I get this:
This is the script Im using:
local ChangeHistory = game:GetService("ChangeHistoryService")
local toolbar = plugin:CreateToolbar("DeleteScriptsInsideObject")
local button = toolbar:CreateButton("456342", "Plugin", "rbxassetid://3090651711", "DeleteScripts")
local selected
local amountOfObjectsSelected = 0
local number = 0
button.Click:Connect(function()
selected = game.Selection:Get()
number = 1
for _, v in pairs(selected) do
amountOfObjectsSelected = amountOfObjectsSelected + 1
end
for i = 1 ,amountOfObjectsSelected, 1 do
for _, v in pairs(selected[number]:GetDescendants()) do
if v.ClassName == "LocalScript" or v.ClassName == "Script" or v.ClassName == "ModuleScript" then
print("Script Deleted")
v:Destroy()
end
end
number = number + 1
end
if amountOfObjectsSelected ~= 0 and number ~= 0 then
print("AddedWaypoint")
ChangeHistory:SetWaypoint("DeletedScripts")
end
amountOfObjectsSelected = 0
number = 0
end)