How do you change a Textbox font by script?

So I was making a word processing software inside roblox (For simulation purposes, I am not trying to compete with large word processing softwares and it wasn’t intended for profiting off it). Anyway, I was trying to change the font of a textbox when a button is clicked.
So:

  1. What do you want to achieve? A button that changes font of a textbox.
  2. What is the issue? I can’t seem to make it work.
  3. What solutions have you tried so far? Checked online but I can’t find one.

script I am trying to use:

script.Parent.MouseButton1Click:Connect(function()
	game.StarterGui.ScreenGui.Frame.TextBox.Text.Font = Enum.Font.AmaticSC
end)

Feel free to ask questions if you don’t seem to understand mine.

do this

script.Parent.MouseButton1Click:Connect(function()
	game.StarterGui.ScreenGui.Frame.TextBox.Font = "AmaticSC"
end)

Font is already a property of the TextBox so you don’t do TextBox.Text.Font, instead you do TextBox.Font. Also I would personally prefer using string for the font since it is faster to type xD

The font which is changing is in the Starter Gui
Everything replicates to player gui.
Therefore instead of addressing like that go through the parents
eg script.Parent…

1 Like

Try this:

local TextBox = -- set this to the textbox but se script.Parent, script.Parent.Parent, etc. 
script.Parent.MouseButton1Click:Connect(function()
	TextBox.Font = "AmaticSC"
end)
1 Like

I just realized a mistake in the code. This code actually changes the TextBox in the StarterGui… You should change the TextBox inside the PlayerGui. Here is the new code

script.Parent.MouseButton1Click:Connect(function()
	game.Players.LocalPlayer.ScreenGui.Frame.TextBox.Font = "AmaticSC"
end)

Make sure that there is only 1 screenGui that has the name “ScreenGui” or else it might choose a different ScreenGui

1 Like

You can change fonts with a String though. I just made a quick test in a new baseplate with this code

while true do
   wait(1)
   script.Parent.Font = "Antique"
   wait(1)
   script.Parent.Font = "SourceSans"
end

And it changed the font every second.

1 Like

Whether or not that is necessarily good practice is a different story though. You also can’t compare fonts the same way. (Enum.Font.SourceSans ~= "SourceSans")
So for consistency you may not want to do that. There’s also the argument that it could perform better, as no implicit casting is done from stringEnum.Font, but that’s mostly negligible. You should run a test though.

3 Likes

True, Enum.Font may perform better than using strings. I just started coding so I don’t prioritize script performance yet lol. But yes, like I said, it is just a personal preference, I don’t recommend anybody to use strings if it performs slower than Enum.Font.

(also let’s stop this conversation since this solved post keeps getting revived xD)

average bad scripter on roblox