ChangeHistoryService is a service that is integral for plugin development. It allows you to undo the actions that your plugin does with waypoints, and some more features. It’s super easy to do, so I’ll show you how.
Important: ChangeHistoryService will only work for plugins. You cannot use it in your actual experience.
This tutorial is also somewhat oriented towards more experienced plugin developers.
1. Making some variables
I will create a variable for ChangeHistoryService, since it’s shorter then typing game.ChangeHistoryService
.
local ChangeHistoryService = game:GetService("ChangeHistoryService")
Add that to the top of your plugin’s code, let’s continue.
2. Making waypoints
Waypoints will basically take the code that was executed before, and run it in reverse. So, if you made a part, it would destroy the part.
Example:
-- This would be enclosed in a function, eg. Button.Click:Connect(function()
-- Make a part
local Part = Instance.new('Part')
Part.Parent = workspace
-- Now, when the user presses Ctrl + Z, the part will be removed
ChangeHistoryService:SetWaypoint('Delete part')
It’s that simple. 'Delete part'
is the description, it’s what is shown when you hover over the undo button.
3. Resetting waypoints
Resetting waypoints could come in handy if you have a custom selector or build tool in your plugin. The animation editor does this when clicked. This is how you reset waypoints:
ChangeHistoryService:ResetWaypoints()
4. Undoing actions
Not to be confused with removing the waypoints, with ResetWaypoints, you can also undo the previous action that you set with a waypoint. It’s identical to hitting Ctrl + Z.
ChangeHistoryService:Undo()
That is about it! Documentation for CHS can be found here. Enjoy.