ChangeHistoryService Tutorial

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.

1 Like

Is this really necessary? Theres an article in the wiki for this already.

1 Like

Some people may prefer devforum posts. I prefer them, so that’s why I made this.

I mean it’s useless then and is creating spam on the tutorials page. There’s already a page for this on the wiki. A topic on the forums is a waste and is just spam.

If you find it as spam, then you don’t find it useful. If someone else finds this useful, they wouldn’t think this is spam. So, carry on with your life. It’s like using OOP for every single script in your game, if you don’t find it useful, you get the point.

2 Likes

Although you may believe this to be helpful to developers, the rules of the category dictate the following:

image

As stated previously, this topic does not convey any more information than the current DevHub article. If anything, the DevHub article documents all CHS methods, while yours only covers Set, Reset, and Undo.