Reference API Roblox

Engine API

Website

Related

Reference API Roblox

StyleRule

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

Member index 12

HistoryMember
640Priority: int
577Selector: string
577SelectorError: string
578GetProperties(): Dictionary
578GetPropertiesResolved(): Dictionary
578GetProperty(name: string): Variant
578GetPropertyResolved(name: string): Variant
664SetProperties(styleProperties: Dictionary): null
578SetProperty(name: string, value: Variant): null
591StyleRulePropertyChanged(styleProperty: string)
inherited from StyleBase
648GetStyleRules(): Instances
664InsertStyleRule(rule: StyleRule, priority: int?): null
648SetStyleRules(rules: Instances): null
580StyleRulesChanged()
inherited from Instance
553Archivable: bool
670Capabilities: SecurityCapabilities
553Name: string
553Parent: Instance
670Sandboxed: bool
616UniqueId: UniqueId
576AddTag(tag: string): null
573ClearAllChildren(): null
462Clone(): Instance
573Destroy(): null
486FindFirstAncestor(name: string): Instance
486FindFirstAncestorOfClass(className: string): Instance
486FindFirstAncestorWhichIsA(className: string): Instance
486FindFirstChild(name: string, recursive: bool = false): Instance
486FindFirstChildOfClass(className: string): Instance
486FindFirstChildWhichIsA(className: string, recursive: bool = false): Instance
486FindFirstDescendant(name: string): Instance
563GetActor(): Actor
486GetAttribute(attribute: string): Variant
462GetAttributeChangedSignal(attribute: string): RBXScriptSignal
631GetAttributes(): Dictionary
648GetChildren(): Instances
462GetDebugId(scopeLength: int = 4): string
486GetDescendants(): Array
486GetFullName(): string
641GetStyled(name: string): Variant
657GetStyledPropertyChangedSignal(property: string): RBXScriptSignal
576GetTags(): Array
576HasTag(tag: string): bool
486IsAncestorOf(descendant: Instance): bool
486IsDescendantOf(ancestor: Instance): bool
664IsPropertyModified(property: string): bool
573Remove(): null
576RemoveTag(tag: string): null
664ResetPropertyToDefault(property: string): null
573SetAttribute(attribute: string, value: Variant): null
462WaitForChild(childName: string, timeOut: double): Instance
648children(): Instances
553clone(): Instance
573destroy(): null
553findFirstChild(name: string, recursive: bool = false): Instance
648getChildren(): Instances
553isDescendantOf(ancestor: Instance): bool
573remove(): null
462AncestryChanged(child: Instance, parent: Instance)
462AttributeChanged(attribute: string)
462ChildAdded(child: Instance)
462ChildRemoved(child: Instance)
462DescendantAdded(descendant: Instance)
462DescendantRemoving(descendant: Instance)
500Destroying()
657StyledPropertiesChanged()
553childAdded(child: Instance)
inherited from Object
647ClassName: string
647className: string
647GetPropertyChangedSignal(property: string): RBXScriptSignal
647IsA(className: string): bool
650isA(className: string): bool
647Changed(property: string)

Description

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

History 15

Members 12

GetProperties

Parameters (0)
No parameters.
Returns (1)
Dictionary

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local coreSheet = ReplicatedStorage:FindFirstChild("CoreSheet")

-- Get reference to style rule
local frameRule = coreSheet.Frame

local props = frameRule:GetProperties()
print(props)
--[[
{
	["AnchorPoint"] = 0.5, 0,
	["BackgroundColor3"] = 1, 0, 0.25
}
]]

History 1

GetPropertiesResolved

Parameters (0)
No parameters.
Returns (1)
Dictionary

History 1

GetProperty

Parameters (1)
namestring
Returns (1)
Variant

Returns the value of a specific property in the StyleRule.

1
2
3
4
5
6
7
8
9
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local coreSheet = ReplicatedStorage:FindFirstChild("CoreSheet")

-- Get reference to style rule
local frameRule = coreSheet.Frame

local prop = frameRule:GetProperty("AnchorPoint")
print(prop) --> 0.5, 0

History 1

GetPropertyResolved

Parameters (1)
namestring
Returns (1)
Variant

History 1

Priority

TypeDefault
int0

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.

History 1

Selector

TypeDefault
string

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

SelectorDescriptionExamples
[class]Matches instances of a GuiObject or UIComponent class."Frame"
"ImageButton"
"UICorner"
.[tag]Matches instances tagged with a CollectionService tag.".Container"
".BlueOnHover"
#[name]Matches instances of a specific Instance.Name."#ModalFrame"
"#CloseButton"
:[state]Matches instances currently in a GuiState.":Hover"

Combinators

CombinatorDescriptionExamples
>Matches instances that are direct children of the previous filter matches."Frame > .Inventory"
>>Matches instances that are descendants of the previous filter matches."ImageButton >> .BlueOnHover"
,Specifies a list of multiple independent selectors for the style rule."Frame.TagA, TextLabel.TagA"
::Creates a phantom UIComponent instance under the previous filter matches and applies the style rule's properties to it."Frame::UICorner"

History 1

SelectorError

TypeDefault
string

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

This property is not replicated. Its interface does not cross the network boundary.
This property is read-only. Its value can be read, but it cannot be modified.

History 1

Tags: [ReadOnly, NotReplicated]

SetProperties

Parameters (1)
stylePropertiesDictionary
Returns (1)
null

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().

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
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:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
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"
})

History 2

SetProperty

Parameters (2)
namestring
valueVariant
Returns (1)
null

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().

1
2
3
4
5
6
7
8
9
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:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
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")

History 1

StyleRulePropertyChanged

Parameters (1)
stylePropertystring

History 1

Settings