Text Anim not working?

Hey everyone! Hope you guys are having a good day, I came across this problem with animating my text, I used this script for another game and it worked, not sure why it isn’t in this game. So basically, I am trying to get the typewriter effect when someone steps on the platform (checkpoint). Nothing happened, so I am not sure how to fix this. Here is my script…

Player = game.Players.LocalPlayer
LS = Player:WaitForChild("leaderstats")
Stage = LS:WaitForChild("Stage")
Txt = script.Parent:WaitForChild("Stage")

StageNames = {
	[1] = 'Level 1';
	[2] = 'Level 2';
	[3] = 'Level 3';
	[4] = 'Level 4';
	[5] = 'Level 5';
	[6] = 'Level 6';
	[7] = 'Level 7';
	[8] = 'Level 8';
	[9] = 'Level 9';
	[10] = 'Level 10'
}

function SoundEffect()
	local StageSound = Instance.new("Sound")
	StageSound.Name = "FutureSound"
	StageSound.SoundId = "rbxassetid://4499400560"
	StageSound.PlaybackSpeed = 1
	StageSound.Volume = 1
	StageSound:Play()
	coroutine.resume(coroutine.create(function()
		wait(1)
		StageSound:Destroy()
	end))
end

function DoStage()
	for i = string.len(StageNames[Stage.Value]), 1 do
		Txt.Text = string.sub(StageNames[Stage.Value],1,i)
		SoundEffect()
		wait()
	end
	wait(2)
	for i = string.len(StageNames[Stage.Value]),0,-1 do
		Txt.Text = string.sub(StageNames[Stage.Value],1,i)
		SoundEffect()
	end
end

Stage.Changed:Connect(function()
	if StageNames[Stage.Value] then
		DoStage()
	end
end)
DoStage()

I have no errors, here is some photos as well.

This is where the text would go, it isn’t transparent, it just has no text in it.

Here is another picture…

These are the stages that are in a folder in workspace.

Stages

If anyone has a solution please let me know, thanks!

1 Like

That will only run if the length of that string is either 0 or 1.
Did you mean to do this?

for i = 1, #StageNames[Stage.Value] do

ohhhh, yeah lol, let me try it out…

ok, I got it working, but it seems to not animate back, like the text gets removed with an animation. the code to do that is

for i = string.len(StageNames[Stage.Value]),0,-1 do
		Txt.Text = string.sub(StageNames[Stage.Value],1,i)
		SoundEffect()
	end
end

But it doesn’t seem to work, and my sound won’t play either.

Got it working, thanks guys :))