Skip to content

Class · inherits StyleBase

StyleRule

Official docs ↗

Defines style properties which override properties on the instances affected by the Selector property.

About StyleRule

Defines style properties which override properties on the instances affected by the Selector property.

Properties 3

  • Priority: intA number that determines how properties of the StyleRule apply relative to the same properties in other StyleRules. Higher priority values take precedence over lower.

    A number that determines how properties of the StyleRule apply relative to the same properties in other StyleRules. Higher priority values take precedence over lower. For example, if a StyleRule with a priority of 10 has an AnchorPoint property of 1, 0, it will take precedence over lower-priority StyleRules with AnchorPoint properties.

  • Selector: stringA string specifying which instances the StyleRule should affect.

    A string specifying which instances the StyleRule should affect. This can be a mix of selectors and combinators to match characteristics such as the class name, instance name, and hierarchy relationships.

    For example, ".Container > ImageLabel.BlueOnHover:Hover" effectively means the style rule overrides every ImageLabel that's a child of an instance tagged with Container (.Container > ImageLabel) and is tagged with BlueOnHover (.BlueOnHover) and is in the GuiState.Hover state (:Hover).

    Selectors

    Combinators

  • SelectorError: stringReadOnlyNotReplicatedA read-only string that displays errors from the Selector property.

    A read-only string that displays errors from the Selector property such as syntax errors, unsupported class types, etc.

Methods 9

  • GetDefaultPropertyTransition() → VariantReturns the default transition applied to all properties of the StyleRule that don't have an explicit transition set.

    Returns the default transition applied to all properties of the StyleRule that don't have an explicit transition set. This is equivalent to calling GetPropertyTransitions() and reading the value at key "*".

  • GetProperties() → DictionaryReturns a dictionary of key-value pairs describing the properties of the StyleRule.

    Returns a dictionary of key-value pairs describing the properties of the StyleRule, for example:

  • GetProperty(name: string) → VariantReturns the value of a specific property in the StyleRule.
  • GetPropertyTransitions() → DictionaryReturns a dictionary of all property transitions set on the StyleRule.

    Returns a dictionary of all property transitions set on the StyleRule. Each key is a property name (string) and each value is a TweenInfo or a string token that defines the transition's timing for that property.

  • SetDefaultPropertyTransition(transitionParams: Variant) → ()Sets or clears a default transition that applies to all properties of the StyleRule that don't have an explicit transition set.

    Sets or clears a default transition that applies to all properties of the StyleRule that don't have an explicit transition set. This is equivalent to calling SetPropertyTransition() with "*" as the property name.

    The transitionParams parameter accepts a TweenInfo that configures the transition's timing. The following TweenInfo properties are used:

    • Time — Duration of the transition in seconds.
    • EasingStyle — The easing function used for interpolation.
    • EasingDirection — The direction of the easing function.
    • DelayTime — Delay in seconds before the transition starts.

    Note that the RepeatCount and Reverses fields of TweenInfo are ignored, as style transitions cannot repeat or reverse automatically.

    A per-property transition set via SetPropertyTransition() takes precedence over the default transition for that property.

  • SetProperties(styleProperties: Dictionary) → ()Lets you declare and set multiple properties of the StyleRule at once.

    Similar to SetProperty() but lets you declare and set multiple properties of the StyleRule at once. Each assignment should be a valid property of the affected GuiObject or UIComponent (UICorner, UIGradient, etc.), and each assigned value should match its property's value type, for example Vector2 for AnchorPoint or Color3 for BackgroundColor3.

    Attempts to assign invalid property names such as "AnchorPt" or "BkColor" will silently fail. Type mismatches such as CFrame for AnchorPoint or UDim2 for BackgroundColor3 will also fail and an error will appear in the Output window.

    To set/update just one property of a StyleRule, see SetProperty().

    local ReplicatedStorage = game:GetService("ReplicatedStorage")
    
    local coreSheet = ReplicatedStorage:FindFirstChild("CoreSheet")
    
    -- Get reference to style rule
    local frameRule = coreSheet.Frame
    
    -- Set rule properties
    frameRule:SetProperties({
        ["AnchorPoint"] = Vector2.new(0.5, 0),
        ["BackgroundColor3"] = Color3.new(1, 0, 0.25)
    })
    

    Note that you can assign tokens as property values through the $ prefix:

    local ReplicatedStorage = game:GetService("ReplicatedStorage")
    
    local coreSheet = ReplicatedStorage:FindFirstChild("CoreSheet")
    local tokensSheet = ReplicatedStorage:FindFirstChild("Tokens")
    
    -- Set tokens (attributes) on tokens sheet
    tokensSheet:SetAttribute("TopCenterAnchor", Vector2.new(0.5, 0))
    tokensSheet:SetAttribute("MainBackgroundColor", Color3.new(0.2, 0.2, 0.3))
    
    -- Get reference to style rule
    local frameRule = coreSheet.Frame
    
    -- Set rule properties
    frameRule:SetProperties({
        ["AnchorPoint"] = "$TopCenterAnchor",
        ["BackgroundColor3"] = "$MainBackgroundColor"
    })
    
  • SetProperty(name: string, value: Variant) → ()Sets or updates a single property of the StyleRule.

    Sets a new property (or modifies an existing property) for the StyleRule. The name parameter should be a valid property of the affected GuiObject or UIComponent (UICorner, UIGradient, etc.), and the assigned value should match the property's value type, for example Vector2 for AnchorPoint or Color3 for BackgroundColor3.

    Attempts to assign invalid property names such as "AnchorPt" or "BkColor" will silently fail. Type mismatches such as CFrame for AnchorPoint or UDim2 for BackgroundColor3 will also fail and an error will appear in the Output window.

    To set multiple properties for a StyleRule at once, see SetProperties().

    local ReplicatedStorage = game:GetService("ReplicatedStorage")
    
    local coreSheet = ReplicatedStorage:FindFirstChild("CoreSheet")
    
    -- Get reference to style rule
    local frameRule = coreSheet.Frame
    
    -- Set rule property
    frameRule:SetProperty("BackgroundColor3", Color3.new(1, 0, 0.25))
    

    Note that you can assign tokens as property values through the $ prefix:

    local ReplicatedStorage = game:GetService("ReplicatedStorage")
    
    local coreSheet = ReplicatedStorage:FindFirstChild("CoreSheet")
    local tokensSheet = ReplicatedStorage:FindFirstChild("Tokens")
    
    -- Set new token (attribute) on tokens sheet
    tokensSheet:SetAttribute("MainBackgroundColor", Color3.new(0.2, 0.2, 0.3))
    
    -- Get reference to style rule
    local frameRule = coreSheet.Frame
    -- Set rule property to use the token as its value
    frameRule:SetProperty("BackgroundColor3, "$MainBackgroundColor")
    
  • SetPropertyTransition(property: string, transitionParams: Variant) → ()Sets or clears the transition for a single property on the StyleRule.

    Sets or clears the transition for a single property on the StyleRule. When a transition is set for a property, any change to that property's styled value will be animated over time instead of applied immediately.

    The transitionParams parameter accepts a TweenInfo that configures the transition's timing. The following TweenInfo properties are used:

    • Time — Duration of the transition in seconds.
    • EasingStyle — The easing function used for interpolation.
    • EasingDirection — The direction of the easing function.
    • DelayTime — Delay in seconds before the transition starts.

    Note that the RepeatCount and Reverses fields of TweenInfo are ignored, as style transitions cannot repeat or reverse automatically.

    To set transitions for multiple properties at once, see SetPropertyTransitions().

  • SetPropertyTransitions(properties: Dictionary) → ()Lets you declare and set transitions for multiple properties of the StyleRule at once.

    Similar to SetPropertyTransition() but lets you declare and set transitions for multiple properties of the StyleRule at once.

    Calling this method replaces all existing transitions on the StyleRule with the provided set. Each key should be a property name (string) and each value should be a TweenInfo or string token defining the transition timing for that property. Passing nil as a value for a key excludes that property from the resulting transitions.

    The following TweenInfo properties are used:

    • Time — Duration of the transition in seconds.
    • EasingStyle — The easing function used for interpolation.
    • EasingDirection — The direction of the easing function.
    • DelayTime — Delay in seconds before the transition starts.

    Note that the RepeatCount and Reverses fields of TweenInfo are ignored, as style transitions cannot repeat or reverse automatically.

    To set/update just one property transition on a StyleRule, see SetPropertyTransition().

StyleRule also has every member of StyleBase. 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.