ChangeHistoryService

Show Deprecated
Not Creatable
Service

Plugin developers must use ChangeHistoryService to tell Studio how to undo and redo changes that their plugins make to experiences by recording. Before making changes, a plugin calls ChangeHistoryService:TryBeginRecording(), remembering the identifier it assigns, then after making changes, the Plugin calls ChangeHistoryService:FinishRecording() to complete the recording.

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

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

Summary

Methods

  • FinishRecording(identifier : string,operation : Enum.FinishRecordingOperation,finalOptions : Dictionary?):()
    Plugin Security

    Communicates to Studio that the identified recording is finished and to take the final operation to complete the recording.

  • Plugin Security

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

  • Plugin Security

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

  • Plugin Security
  • Redo():()
    Plugin Security

    Executes the last action that was undone.

  • Plugin Security

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

  • SetEnabled(state : boolean):()
    Plugin Security

    Sets whether or not the ChangeHistoryService is enabled.

  • SetWaypoint(name : string):()
    Plugin Security

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

  • TryBeginRecording(name : string,displayName : string?):string?
    Plugin Security

    Begins tracking changes made to the data model into a recording.

  • Undo():()
    Plugin Security

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

Events

Properties

Methods

FinishRecording

()
Plugin Security

Parameters

identifier: string
finalOptions: Dictionary

Returns

()

Code Samples

ChangeHistoryService:TryBeginRecording

local ChangeHistoryService = game:GetService("ChangeHistoryService")
local Selection = game:GetService("Selection")
local toolbar = plugin:CreateToolbar("Example Plugin")
local button = toolbar:CreateButton("Neon it up", "", "")
button.Click:Connect(function()
local parts = {}
for _, part in pairs(Selection:Get()) do
if part:IsA("BasePart") then
parts[#parts + 1] = part
end
end
if #parts < 1 then
-- Nothing to do.
return
end
local recording = ChangeHistoryService:TryBeginRecording("Set selection to neon")
if not recording then
-- Handle error here. This indidcates that your plugin began a previous
-- recording and never completed it. You may only have one recording
-- per plugin active at a time.
return
end
for _, part in pairs(parts) do
part.Material = Enum.Material.Neon
end
ChangeHistoryService:FinishRecording(recording, Enum.FinishRecordingOperation.Commit)
end)

GetCanRedo

Plugin Security

Returns

GetCanUndo

Plugin Security

Returns

IsRecordingInProgress

Plugin Security

Parameters

identifier: string

Returns

Redo

()
Plugin Security

Returns

()

ResetWaypoints

()
Plugin Security

Returns

()

SetEnabled

()
Plugin Security

Parameters

state: boolean

Returns

()

SetWaypoint

()
Plugin Security

Parameters

name: string

Returns

()

Code Samples

ChangeHistoryService:SetWaypoint

local ChangeHistoryService = game:GetService("ChangeHistoryService")
local Selection = game:GetService("Selection")
local toolbar = plugin:CreateToolbar("Example Plugin")
local button = toolbar:CreateButton("Neon it up", "", "")
button.Click:Connect(function()
local parts = {}
for _, part in pairs(Selection:Get()) do
if part:IsA("BasePart") then
parts[#parts + 1] = part
end
end
if #parts > 0 then
-- Calling SetWaypoint before the work will not cause any issues, however
-- it is redundant, only the call AFTER the work is needed.
--ChangeHistoryService:SetWaypoint("Setting selection to neon")
for _, part in pairs(parts) do
part.Material = Enum.Material.Neon
end
-- Call SetWaypoint AFTER completing the work
ChangeHistoryService:SetWaypoint("Set selection to neon")
else
-- Nothing to do. You do not need to call SetWaypoint in the case where
-- the action did not end up making any changes to the experience.
end
end)

TryBeginRecording

Plugin Security

Parameters

name: string
displayName: string

Returns

Code Samples

ChangeHistoryService:TryBeginRecording

local ChangeHistoryService = game:GetService("ChangeHistoryService")
local Selection = game:GetService("Selection")
local toolbar = plugin:CreateToolbar("Example Plugin")
local button = toolbar:CreateButton("Neon it up", "", "")
button.Click:Connect(function()
local parts = {}
for _, part in pairs(Selection:Get()) do
if part:IsA("BasePart") then
parts[#parts + 1] = part
end
end
if #parts < 1 then
-- Nothing to do.
return
end
local recording = ChangeHistoryService:TryBeginRecording("Set selection to neon")
if not recording then
-- Handle error here. This indidcates that your plugin began a previous
-- recording and never completed it. You may only have one recording
-- per plugin active at a time.
return
end
for _, part in pairs(parts) do
part.Material = Enum.Material.Neon
end
ChangeHistoryService:FinishRecording(recording, Enum.FinishRecordingOperation.Commit)
end)

Undo

()
Plugin Security

Returns

()

Events

OnRecordingFinished

Plugin Security

Parameters

name: string
displayName: string
identifier: string
finalOptions: Dictionary

OnRecordingStarted

Plugin Security

Parameters

name: string
displayName: string

OnRedo

Plugin Security

Parameters

waypoint: string

OnUndo

Plugin Security

Parameters

waypoint: string