Class · inherits StyleBase
StyleRule
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 theStyleRuleapply relative to the same properties in otherStyleRules. Higher priority values take precedence over lower.A number that determines how properties of the
StyleRuleapply relative to the same properties in otherStyleRules. Higher priority values take precedence over lower. For example, if aStyleRulewith a priority of10has anAnchorPointproperty of1, 0, it will take precedence over lower-priorityStyleRuleswithAnchorPointproperties.Selector
: stringA string specifying which instances theStyleRuleshould affect.A string specifying which instances the
StyleRuleshould 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 everyImageLabelthat's a child of an instance tagged withContainer(.Container > ImageLabel) and is tagged withBlueOnHover(.BlueOnHover) and is in theGuiState.Hoverstate (:Hover).Selectors
Combinators
Methods 9
GetDefaultPropertyTransition
() → VariantReturns the default transition applied to all properties of theStyleRulethat don't have an explicit transition set.Returns the default transition applied to all properties of the
StyleRulethat don't have an explicit transition set. This is equivalent to callingGetPropertyTransitions()and reading the value at key"*".GetProperties
() → DictionaryReturns a dictionary of key-value pairs describing the properties of theStyleRule.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 theStyleRule.GetPropertyTransitions
() → DictionaryReturns a dictionary of all property transitions set on theStyleRule.Returns a dictionary of all property transitions set on the
StyleRule. Each key is a property name (string) and each value is aTweenInfoor 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 theStyleRulethat don't have an explicit transition set.Sets or clears a default transition that applies to all properties of the
StyleRulethat don't have an explicit transition set. This is equivalent to callingSetPropertyTransition()with"*"as the property name.The
transitionParamsparameter accepts aTweenInfothat configures the transition's timing. The followingTweenInfoproperties 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
RepeatCountandReversesfields ofTweenInfoare 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 theStyleRuleat once.Similar to
SetProperty()but lets you declare and set multiple properties of theStyleRuleat once. Each assignment should be a valid property of the affectedGuiObjectorUIComponent(UICorner,UIGradient, etc.), and each assigned value should match its property's value type, for exampleVector2forAnchorPointorColor3forBackgroundColor3.Attempts to assign invalid property names such as
"AnchorPt"or"BkColor"will silently fail. Type mismatches such asCFrameforAnchorPointorUDim2forBackgroundColor3will also fail and an error will appear in the Output window.To set/update just one property of a
StyleRule, seeSetProperty().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 theStyleRule.Sets a new property (or modifies an existing property) for the
StyleRule. Thenameparameter should be a valid property of the affectedGuiObjectorUIComponent(UICorner,UIGradient, etc.), and the assigned value should match the property's value type, for exampleVector2forAnchorPointorColor3forBackgroundColor3.Attempts to assign invalid property names such as
"AnchorPt"or"BkColor"will silently fail. Type mismatches such asCFrameforAnchorPointorUDim2forBackgroundColor3will also fail and an error will appear in the Output window.To set multiple properties for a
StyleRuleat once, seeSetProperties().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 theStyleRule.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
transitionParamsparameter accepts aTweenInfothat configures the transition's timing. The followingTweenInfoproperties 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
RepeatCountandReversesfields ofTweenInfoare 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 theStyleRuleat once.Similar to
SetPropertyTransition()but lets you declare and set transitions for multiple properties of theStyleRuleat once.Calling this method replaces all existing transitions on the
StyleRulewith the provided set. Each key should be a property name (string) and each value should be aTweenInfoor string token defining the transition timing for that property. Passingnilas a value for a key excludes that property from the resulting transitions.The following
TweenInfoproperties 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
RepeatCountandReversesfields ofTweenInfoare ignored, as style transitions cannot repeat or reverse automatically.To set/update just one property transition on a
StyleRule, seeSetPropertyTransition().
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.