Cannot set FontFace's properties

Hello,

I was in a process of overhauling a plugin of mine when I found out that you cannot individually set any of FontFace’s properties.


Reproduction Footage

Reproduction Steps

To replicate this behavior, open the following reproduction place…

TextExample.rbxl (37.2 KB)

…and insert the following into the command bar

game.StarterGui.ScreenGui.TextLabel.FontFace.Style = Enum.FontStyle.Italic; game.StarterGui.ScreenGui.TextLabel.FontFace.Bold = false

Hoping for this to get fixed.

1 Like

We’ve filed a ticket into our internal database for this issue, and will come back as soon as we have updates!

Thanks for flagging!

2 Likes

Unfortunately, this is expected behavior. When you read the FontFace property, it actually creates a copy of the object and returns it. When you set the properties of that object, it only sets them on the copy and not on the original. This is a limitation that we can’t fix currently.

The workaround is a bit ugly, which is to do something like this instead:

local label = game.StarterGui.ScreenGui.TextLabel
local font = label.FontFace
-- Set properties on copy
font.Style = Enum.FontStyle.Italic
font.Bold = false
-- Set to updated copy
label.FontFace = font

Or like this:

local label = game.StarterGui.ScreenGui.TextLabel
label.FontFace = Font.new(
	label.FontFace.Family,
	Enum.FontWeight.Regular,
	Enum.FontStyle.Italic
)

The reason this isn’t noticeable with other data types like Vector3 is because their properties can’t be modified like this. For example, workspace.Baseplate.Position.X = 2 will throw an error saying X cannot be assigned to.

In the future, we’re hoping to add a script analysis warning in cases like this, to help avoid bugs caused by this.

6 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.