Typewriter breaks when a player joins the game while it runs

The tiitle basically explains my issue. I would love a fix.

Not sure why exactly you are doing this on the server.

You can just have the typewriter run on the client by copy pasting the for loop into a localscript under the gui element and you should be good.

this is just a copypaste for an example. What is happening is that it’s a script in the workspace that is controlling the messages that show up.

It breaks if someone joins while the typewriter message is being typed on screen

It breaks because the player that joined is not in the table you got with players:GetPlayers() at the time of execution. You should use a players.PlayerAdded connection instead.

Also, this isn’t a… great way to do a typewriter effect. Roblox has actually relatively recently added a MaxVisibleGraphemes property that makes it a whole lot simpler. Here’s how you would do it:

local textLabel = player.PlayerGui.MessageBox.Frame.TextLabel
textLabel.Text = "This is just an example message."

for count = 0, string.len(textLabel.Text) do
    textLabel.MaxVisibleGraphemes = count
    
    task.wait()
end