I’m wanting to get the length of the word, as well as length of each individual character. Now, these both SHOULD equal the same amount (when adding all the character lengths together)
local WordLength = TextService:GetTextSize(
word,
TextSize,
Properties.Font,
Vector2.new(SCREEN_SIZE.X, TextSize)
).X
-- Create new TextLabel (store the word)
local WordLabel = TextLabel:Clone()
WordLabel.TextSize = TextSize
WordLabel.Text = word
WordLabel.TextTransparency = 1
WordLabel.TextStrokeTransparency = 1
-- Seperate the word into characters
local CharPos = 0
local i = 1
for first, last in utf8.graphemes(word) do
local Character = string.sub(word, first, last)
local CharacterLength = TextService:GetTextSize(
Character,
TextSize,
Properties.Font,
Vector2.new(SCREEN_SIZE.X, TextSize)
).X
CharPos += CharacterLength
i += 1
end
print(word, WordLength, CharPos) --// WordLength and CharPos SHOULD be the same number
However, I get cases where CharPos is anywhere from 2-10 pixels longer than the word. This should not be happening, but I can’t figure out why it’s happening anyway.
Output example
07:49:25.297 Hello! 72 74 - Client - RichText:291
07:49:25.298 I 10 10 - Client - RichText:291
07:49:25.298 can 38 38 - Client - RichText:291
07:49:25.298 trigger 70 70 - Client - RichText:291
07:49:25.299 laugh 57 57 - Client - RichText:291
07:49:25.299 effects. 70 73 - Client - RichText:291
Most are correct, however a few go off