Parent setting error when undoing action using ChangeHistoryService

Hello guys, just today have started learning how to develop plugins and have already made some great progress. However, I have run into an issue that I am having trouble with solving.

My plugin manages scripts in many different locations and quickly allows you to open and delete them, as well as providing other data.

The error in the output
image

The script

local update_service = game:GetService("ChangeHistoryService");

update_service:SetWaypoint("Before");
v:Destroy();
update_service:SetWaypoint("After");

v is the script I am looking to delete. I looked at some info on the API reference manual on how to set up the plugin so I can undo things. I am looking to see how I can still delete the script and press ctrl + X/undo to get the script back. Bumping this up, and adding another issue…

When the GUI is created and I undo it, it causes the GUI in the widget to disappear and a bunch of scripts and models in the workspace to appear.

This is the script I am using to insert the UI

			widget = plugin:CreateDockWidgetPluginGui("Script Orginizer", widgetInfo);
			widget.Title = "Script Orginizer";  -- Optional widget title;



			local asset = asset_service:LoadAsset(6748066734);
			asset.Parent = workspace;
			local fold = asset:FindFirstChildWhichIsA("Model")

			for i,v in pairs(fold:GetChildren()) do
				if v.Name == "FrameEnlister" then
					frame_info_model = v
					v.Parent = nil
					break
				end
			end


			for i,v in pairs(fold:GetChildren()) do
				v.Parent = widget
			end

			asset:Destroy()
			widget.Enabled = true;
			UpdateScreen()

Happens because you’re destroying the instance. Refer to this thread:

1 Like

Thanks! It works perfectly now. This might be asking a little too much but what could be the cause of the GUI disappearing when i press undo?

I’m not sure since I’ve never actually used ChangeHistoryService myself, sorry.

1 Like