ChangeHistoryService

Show Deprecated
Not Creatable
Service

Plugin developers must use ChangeHistoryService to tell Studio how to undo and redo changes which their plugins make to experiences. Plugins must call ChangeHistoryService:SetWaypoint() after making a set of changes, as failing to do so will cause unexpected undo and redo behavior. No explicit set of changes is registered by the plugin; instead, calling SetWaypoint automatically includes all of the property changes made since the last waypoint was set.

Plugins may also programmatically invoke an undo or redo through ChangeHistoryService:Undo() or ChangeHistoryService:Redo().

Note that ChangeHistoryService is not enabled at runtime, so calling its methods in a running experience has no effect.

Summary

Properties

Events

OnRedo(waypoint: string): RBXScriptSignal  

Fired when the user reverses the undo command. Waypoint describes the type action that has been redone.

OnUndo(waypoint: string): RBXScriptSignal  

Fired when the user undoes an action in studio. Waypoint describes the type action that has been undone.

Methods


Returns whether there are actions that can be redone, and, if there are, returns the last of them.


Returns whether there are actions that can be undone, and, if there are, returns the last of them.

Redo(): void  

Executes the last action that was undone.

ResetWaypoints(): void  

Clears the history, causing all undo/redo waypoints to be removed.

SetEnabled(state: boolean): void  

Sets whether or not the ChangeHistoryService is enabled.

SetWaypoint(name: string): void  

Sets a new waypoint which can be used as an undo or redo point.

Undo(): void  

Undos the last action taken, for which there exists a waypoint.

Properties

Events

OnRedo

Plugin Security

Fired when the user reverses the undo command. Waypoint describes the type action that has been redone.

Parameters

waypoint: string

OnUndo

Plugin Security

Fired when the user undoes an action in studio. Waypoint describes the type action that has been undone.

Parameters

waypoint: string

Methods

GetCanRedo

Plugin Security

Returns whether there are actions that can be redone, and, if there are, returns the last of them.


Returns

GetCanUndo

Plugin Security

Returns whether there are actions that can be undone, and, if there are, returns the last of them.


Returns

Redo

void
Plugin Security

Executes the last action that was undone.


Returns

void

ResetWaypoints

void
Plugin Security

Clears the history, causing all undo/redo waypoints to be removed.


Returns

void

SetEnabled

void
Plugin Security

Sets whether or not the ChangeHistoryService is enabled. When set to false, the undo/redo list is cleared, and does not repopulate. When set to true again, the original list is not restored, but further operations append to the list once more

Parameters

state: boolean

Returns

void

SetWaypoint

void
Plugin Security

ChangeHistoryService tracks plugin history as a stream of property changes. SetWaypoint creates a cut in that stream of property changes so that the undo and redo actions know where to stop.

By convention, user-invoked actions in Studio must call SetWaypoint after completing their set of changes to the experience. Calling it before a set of changes may clean up another misbehaving plugin which failed to set a waypoint, but it's a poor reason to justify such usage in your own plugin.

Parameters

name: string

Returns

void

Code Samples

ChangeHistoryService:SetWaypoint

1local ChangeHistoryService = game:GetService("ChangeHistoryService")
2local Selection = game:GetService("Selection")
3
4local toolbar = plugin:CreateToolbar("Example Plugin")
5local button = toolbar:CreateButton("Neon it up", "", "")
6
7button.Click:Connect(function()
8 local parts = {}
9 for _, part in pairs(Selection:Get()) do
10 if part:IsA("BasePart") then
11 parts[#parts + 1] = part
12 end
13 end
14
15 if #parts > 0 then
16 -- Calling SetWaypoint before the work will not cause any issues, however
17 -- it is redundant, only the call AFTER the work is needed.
18 --ChangeHistoryService:SetWaypoint("Setting selection to neon")
19
20 for _, part in pairs(parts) do
21 part.Material = Enum.Material.Neon
22 end
23
24 -- Call SetWaypoint AFTER completing the work
25 ChangeHistoryService:SetWaypoint("Set selection to neon")
26 else
27 -- Nothing to do. You do not need to call SetWaypoint in the case where
28 -- the action did not end up making any changes to the experience.
29 end
30end)

Undo

void
Plugin Security

Undos the last action taken, for which there exists a waypoint.


Returns

void