MotionFX
The module table you get from require(ReplicatedStorage.MotionFX). Call every function with a colon: MotionFX:Play(...).
local MotionFX = require(ReplicatedStorage.MotionFX)
Properties
MotionFX.Enum
FXPreset and view names, grouped as Impact, Injury, View and Primitives. Typing MotionFX.Enum. autocompletes the groups and their names. Each entry is just its own string, so FX.Impact.Explosion == "Explosion". See Enum groups.
MotionFX.Drive
DriveLibThe driver library: Constant, Tween, Envelope, Noise, Spring, Bind, Cycle, Modulate, Sum, Sequence and Map. See Drive.
MotionFX.Track
TrackLibReady-made tracks: Shake, Kick, Punch, Zoom, Edge, Flash, Blur, Tint, Overlay and Sound. Each returns an ordinary track with sensible defaults. See Ready-made tracks.
MotionFX.Overlays
OverlaysA frozen table of named, ready-to-use overlay sheets, used with Track.Overlay. Its names autocomplete. See Overlay presets.
MotionFX.Overlay
OverlayLibHelpers for overlay sheets:
| Function | Description |
|---|---|
FromFolder(folder: Instance): OverlaySheet | Builds a sheet from children named 1, 2, 3… (Decals, Textures, ImageLabels or StringValues), sorted as numbers. See numbered images. |
Preload(sheet: OverlaySheet) | Loads a sheet's images and keeps them ready to draw, so the overlay doesn't blink the first time. It yields until they're ready, so run it in its own thread. See Preloading. |
Unload(sheet: OverlaySheet) | Lets go of a preloaded sheet's images, freeing their memory once nothing is showing them. |
FrameCount(sheet: OverlaySheet): number | How many frames a sheet holds: its Frames, or every cell of every image. |
task.spawn(MotionFX.Overlay.Preload, MotionFX.Overlays.SnowOnScreen)
Not to be confused with MotionFX.Overlays, the table of ready-made sheets.
MotionFX.Sounds
SoundsA frozen table of named sound asset ids used by the presets. Its names autocomplete. You can use them in your own Sound tracks too. See Sounds.
MotionFX.ViewSettings
ViewSettingsA live settings table for views and smoothing. Change a field and the change applies on the next frame. See View settings.
MotionFX.ViewSettings.ShoulderOffset = Vector3.new(-2.75, 0.5, 6.5) -- left shoulder
Definitions
MotionFX:Create
methodMotionFX:Create(name: string, definition: EffectDefinition, options: CreateOptions?): string
Registers a named effect so that Play(name) can run it, and returns name. The definition is validated right away. By default it errors if name is already taken, including by a built-in preset. Pass { Overwrite = true } to replace it.
| Parameter | Type | Description |
|---|---|---|
name | string | A non-empty unique name. |
definition | EffectDefinition | Tracks plus timing and stacking rules. |
options optional | CreateOptions | Overwrite: boolean? |
MotionFX:Create("Stagger", {
Duration = 1.2,
FadeOut = 0.4,
Retrigger = "Refresh",
Tracks = {
{ Primitive = "Rotation", Driver = Drive.Spring({ Kick = Vector3.new(0, 0, 6), Frequency = 2, Damping = 0.3 }) },
{ Primitive = "Blur", Driver = Drive.Constant(6), Delay = 0.1 },
},
})
MotionFX:Remove
methodMotionFX:Remove(name: string): ()
Unregisters a definition. Instances that are already running keep playing. Later Play(name) calls error.
MotionFX:Has
methodMotionFX:Has(name: string): boolean
Returns true if an effect with that name is registered. Built-in presets count.
if not MotionFX:Has("Stagger") then
MotionFX:Create("Stagger", definition)
end
Playback
MotionFX:Play
methodMotionFX:Play(name: PresetName, options: PlayOptions?): Handle
Starts a registered effect and returns its Handle. What happens when the effect is already running depends on its Retrigger policy. Errors if no effect is registered under that name.
| Option | Type | Description |
|---|---|---|
Intensity | number? | Master scale, 0..1 or higher. Default 1. |
Duration | number? | Overrides the definition's duration. |
Speed | number? | Time scale for the drivers. Default 1. |
FadeIn | number? | Overrides the definition's FadeIn. |
FadeOut | number? | Overrides the definition's FadeOut. |
Seed | number? | Makes noise deterministic, for example to replicate the same shake to every client. |
Params | { [string]: any }? | Passed to the definition's Build function. See preset Params. |
local handle = MotionFX:Play(FX.Impact.Earthquake, { Intensity = 0.5, Speed = 1.25 })
MotionFX:Play("Shake", { Params = { Sound = false } })
MotionFX:Stop
methodMotionFX:Stop(name: PresetName, fadeTime: number?): ()
Stops every running instance of name. With no fadeTime, each instance uses its own FadeOut.
MotionFX:StopAll
methodMotionFX:StopAll(fadeTime: number?): ()
Stops every running effect, including those started with Apply. Views and smoothing are not affected.
MotionFX:GetActive
methodMotionFX:GetActive(name: PresetName?): { Handle }
Returns the handles that haven't finished yet, including those in the "Stopping" state. Pass a name to only get that effect's handles.
local burning = #MotionFX:GetActive("Burning") > 0
MotionFX:Apply
methodMotionFX:Apply(primitive: PrimitiveName, driver: Driver<T>, options: PlayOptions?): Handle
Drives one primitive directly, without a named effect. Depending on the driver, the result is an instant set (Constant), an animation (Tween, Spring…) or a permanent binding (Bind). Every call is independent, with no retrigger rules. The overloads are typed so that each primitive only accepts its own value type. "Sound" can't be applied.
-- Zoom in 10 degrees over 0.25 s, hold, then release when the aim ends
local aim = MotionFX:Apply("FOV", Drive.Sequence(
Drive.Tween(0, -10, 0.25),
Drive.Constant(-10)
))
-- ...
aim:Stop(0.2)
Views and smoothing
Views and smoothing stay on until you change them. See Views & Smoothing for how each view behaves.
MotionFX:SetView
methodMotionFX:SetView(view: ViewName, transitionTime: number?): ()
Switches to "Default", "FirstPerson", "ThirdPerson" or "BackView", blending over transitionTime (0.4 s by default, and 0 snaps). Errors on an unknown view name.
MotionFX:SetView(FX.View.ThirdPerson, 0.6)
MotionFX:ToggleView
methodMotionFX:ToggleView(view: ViewName, transitionTime: number?): ViewName
Switches to view. If view is already active, switches back to "Default". Returns the new view.
MotionFX:GetView
methodMotionFX:GetView(): ViewName
Returns the current view.
MotionFX:SetSmoothing
methodMotionFX:SetSmoothing(enabled: boolean, responsiveness: number?): ()
Makes the camera ease after the mouse instead of snapping to it, in any view. responsiveness (roughly 1 / seconds, default 12) must be greater than 0. It is stored in ViewSettings.Responsiveness.
MotionFX:SetSmoothing(true, 8) -- softer follow
MotionFX:IsSmoothing
methodMotionFX:IsSmoothing(): boolean
Returns whether smoothing is on.
Handle
Play and Apply return a handle that controls one running instance.
Handle fields
read-only| Field | Type | Description |
|---|---|---|
Id | number | Unique, increasing id. |
Name | string | Effect name. Apply handles are named <Apply:FOV> and similar. |
State | "Playing" | "Stopping" | "Finished" | The handle's lifecycle state. |
Intensity | number | The current master intensity. During a SetIntensity fade it is the in-between value. |
Handle:SetIntensity
methodhandle:SetIntensity(value: number, fadeTime: number?): ()
Retargets the master intensity, either instantly or at a constant rate over fadeTime. Use it to drive an effect's strength from gameplay. It does nothing on a finished handle.
local damage = MotionFX:Play(FX.Injury.BrainDamage, { Duration = math.huge })
damage:SetIntensity(0.3, 1) -- ease down to 30% over a second
Handle:Stop
methodhandle:Stop(fadeTime: number?): ()
Fades the effect out over fadeTime seconds, or over its FadeOut if you pass nothing, and then finishes it. Sounds fade as well. A fade time of 0 finishes immediately. It only works while the handle is "Playing".
Handle.Finished
Signal<>Fires once when the handle reaches "Finished", whether it ran out or was stopped. It supports Connect, Once and Wait. Callbacks run in new threads via task.spawn.
MotionFX:Play("Concussion").Finished:Once(function()
print("back to normal")
end)