Playing sound in a for loop?

I’m doing a typewriter effect for a TextLabel and I’m also trying to play a sound with it. Unfortunately, no matter where I put it in the for loop, it just doesn’t play. Anyone know how I can make the for loop also play the sound while the text is being typed?

local text = "Welcome to another one of my idiotic games"
local sound = game.Workspace.Sound

wait(5)

for i = 1, #text do 
	script.Parent.Text = string.sub(text, 1, i)
	wait(0.005)
	
		end

put Sound:Play after the
script.Parent.Text = string.sub(text, 1, i)

Check if the Sound’s Volume is 0, and use sound:Play()

First thing I tried. Whenever I do so, the sound will only play once after all of the text is typed out

The sound does kind of play when I insert it into the for loop. But only once after the text is fully typed out

1 Like

Have you tried playing the sound then stop it after the wait? so it should loop play wait stop until for loop is complete

Actually, could you try changing it to a LocalScript inside StarterPack and & try this instead?

local text = "Welcome to another one of my idiotic games"
local sound = game.Workspace.Sound

wait(5)

for i = 1, #text do 
    game.SoundService:PlayLocalSound(Sound)
	script.Parent.Text = string.sub(text, 1, i)
	wait(0.005)
end

Reference:

Not sure if this will work but give it a shot I suppose?

1 Like

Now it simply doesn’t play when I do that

Actually it is in a LocalScript and why would it need to be in StarterPack? It’s a GUI

Oh okay, just try doing SoundService’s PlayLocalSound function instead then maybe?

1 Like

it could be too fast for the sound to do my loop ( .005 sec is really quick)

1 Like

That did it and also now I know about PlayLocalSound. (Also how do you highlight those API stuff like PlayLocalSound?)

Just copy & paste the link, and it should preview it as a reference lol
Examples: