Emoji loading in with a X box?

I’m trying to make a text loading in effect and it’s going well, but the emojis are loading in with a box and an X in it, then the actual emoji loads in. I’ve tried changing the emoji’s but that seemed to not change anything, is there any way I can fix this?

https://gyazo.com/46585b4b71f65f21fbea7fa27262c125

local text = "🔊 Turn up your sound for the best experience! 🔊"

r = 1
while true do wait()
   if r == 1 then
      for i = 0, # text do
      script.Parent.Text = string.sub(text,1,i)
       wait(.065)
       end
           r = 2
	       wait(2)
           end
end
--- I know the code's not the best

image

To put it simply, this particular emoji is 4 characters long. So, as you load the message character by character it loads an incomplete and unrecognised character - which is unrepresentable in Roblox, hence it shows up as the square box.

As for fixing this, I’m not entirely sure - find some way of detecting an emoji of variable length and display it all toghether.

1 Like

Consider using the utf8 library instead of the string library for handling Unicode characters (that includes strings with international characters or emoji), as the default string library can only handle ASCII characters natively. You can use the utf8 functions for getting the indexes you need to get the proper substrings.

3 Likes

Oh, that makes sense, thanks! :grinning:

Using @Elttob’s excellent suggestion of the utf8 library (which I didn’t realise existed until now!), you can achieve what you’re looking for using this:

local text = "🔊 Turn up your sound for the best experience! 🔊"
local r = 1

while true do
	wait()
	if r == 1 then
		local displayText = ""
		for position, codepoint in utf8.codes(text) do
			displayText = displayText..utf8.char(codepoint)
			script.Parent.Text = displayText
			wait(.065)
		end
		r = 2
		wait(2)
	end
end
2 Likes

Thanks, didn’t know that existed till now also!