Skip to content

Class · inherits Instance

ValueCurve

Official docs ↗

A sorted list of time-value pairs that define a curve. Used to animate any type of value.

About ValueCurve

An instance representing a 1D value curve encoded via a sorted list of ValueCurveKeys. The shape of the interpolation curve between two keys is determined by the ValueCurveKey.Interpolation type.

Not all value types (for example, strings and other non-numerical types) may perform Linear or Cubic interpolation. These types will revert to Constant interpolation if necessary.

Properties 2

  • Length: intReadOnlyNotReplicatedNumber of keys in the value curve.
  • ValueType: stringReadOnlyNotReplicatedRead-only value indicating the type held in this curve.

    Read-only value indicating the type held in this curve, or the string "Nil" if there are no keys.

Methods 8

  • GetKeyAtIndex(index: int) → ValueCurveKeyReturns a copy of a key at a given index.
  • GetKeyIndicesAtTime(time: float) → ArrayReturns the index of the last and first key of a period of time.

    The first item in the returned array is the index of the last key with time less than or equal to time (or the lesser of either 1 or the curve length if no key was found). The second item in the returned array is the index of the first key with time greater than or equal to time (or the curve length if no key was found satisfying the inequality).

  • GetKeys() → ArrayReturns a copy of all the keys in the ValueCurve as a Luau array of ValueCurveKeys.

    Returns a copy of all the keys in the ValueCurve as a Luau array of ValueCurveKeys.

  • GetValueAtTime(time: float) → Variant?Samples the value curve at a given time passed as argument.
  • InsertKey(key: ValueCurveKey) → ArrayAdds the key passed as an argument to this curve. If a key at the same time is found, it will be replaced.

    Adds the key passed as an argument to this curve. If a key at the same time is found, it will be replaced. In the returned array, the first value is true if a key was added or false if a previous key was replaced; the second value is the index at which the marker was added.

    If there are not yet any keys, then the key may be added. If keys exist, the type of the value must match those of existing keys; otherwise a message is printed and {false, -1} is returned.

  • InsertKeyValue(time: float, value: Variant, Interpolation: KeyInterpolationMode) → ArrayCreates a key for the given value and inserts it at the given time. If a key at the same time is found, it will be replaced.

    Creates a ValueCurveKey from the given arguments and inserts it in this curve. If a key at the same time is found, it will be replaced. In the returned array, the first value is true if a key was added or false if a previous key was replaced; the second value is the index at which the marker was added.

    If there are not yet any keys, then the key may be added. If keys exist, the type of the value must match those of existing keys; otherwise a message is printed and {false, -1} is returned.

  • RemoveKeyAtIndex(startingIndex: int, count: int = 1) → intRemoves a given number of keys starting from a given index.

    Removes a given number (count) of keys starting from the startingIndex index and returns the number of keys that were removed.

  • SetKeys(keys: Array) → intResets this curve's keys using the ValueCurveKey array passed as an argument.

    Resets this curve's keys using the ValueCurveKey array passed as an argument. Keys in the keys array are sorted in ascending time order before insertion, and keys at duplicated times are removed in a stable manner.

    Returns the number of keys actually inserted. Keys previously stored in this curve are removed before the keys passed as arguments are added.

    The keys must all contain values of the same type. And that type must match any existing keys. Otherwise a message is printed, the keys are not added, and 0 is returned.

ValueCurve also has every member of Instance. Deprecated and Roblox-only members are hidden.

Reference text from the Roblox Creator Documentation, licensed CC BY 4.0, reorganized by rbxtoolshub.com · Studio 0.743.0.7431133.