Typewriter Effect Issue

Hey everyone,

I have a simple issue on a typewriting effect text I made earlier today, everything is working fine with the typewriting effect. However, I also have a clicking sound that I want to play whenever each letter is typed. But, for some reason, it doesn’t play the sound all the way.

Main Issue: Sound doesn’t play when each word is typed, I think it’s asking the sound to play too fast each time.
I have tried using RunService to try and make it so the sound plays on each letter but it doesn’t work.
Can someone help out?

Here is my code:

        for i = 1, #guiText do
		    guiText.Text = string.sub(guiText,1,i)
		    wait(0.025)
		    clickSound:Play()
        end	

Let me just make this clear, you need a typewriter effect where when every letter appears, a sound plays?

Yeah, I should have explained it more sorry.

1 Like

You have the wait before the sound, try replacing them like

for  i = 1, #guiText do
	guiText.Text = string.sub (guiText, 1, i)
	clickSound:Play()
	wait(0.025)
end

Let me know if that worked because it did for me…

Once again the sound only works for some letters not for all of them, I used RunService a long time ago to fix this problem which worked, but then I forgot.

the sound only works for some letters not for all of them

That happens because your sound is longer then 0.025 seconds. When the wait ends, the function repeats therefore it resets the sound.

you should use 2 events to trigger these functions

you should go find that piece of code

Let me try and use a smaller sound, thanks.

1 Like

I can’t find it anymore I probably deleted it, lol.

You can also try using the same sound but with increasing the PlaybackSpeed property to match the sound end. It also brings the pitch up though…

Spamming sound instances isnt good practice, the engine can’t take too much sound instances.

What you can do is loop the audio file for the duration of the typing sequence (can calculate this using the wait time (0.025) times the length of the guiText. You also may have to edit the pitch (depending on the sound ID, so play around with it)

Once the sound reaches the time threshold, stop the sounds from playing so that it kills the loop.

1 Like

Instead of the 0.025 wait time, put the wait time to as long as the sound is

Instead of playing one sound each time a letter is being written, create new sound and play the audio.
Once the new audio finishes, destroy the Sound instance.

Good luck on the project, and have a nice day!

local ID = yoursoundidhere;

local function NewSound(id)
    if not id then error("Function 'NewSound' ERROR: No sound ID has been provided"); end;

    local sound = Instance.new("Sound");
    sound.SoundId = id;
    sound.Parent = game.SoundService;
    sound:Play();

    sound.Ended:Connect(function()
        sound:Destroy();
    end;

    return sound;
end

NewSound(ID);

can I have a ID of your audio? or try this.

for i=1,#guiText do
     guiText.Text = string.sub(guiText,1,i)
     local Audio = clickSound:Clone()
     Audio.Parent = script.Parent
     Audio.PlaybackSpeed = math.random(9,11)/10 -- you can delete this thing, just making audio realistic
     Audio:Play()
     coroutine.resume(coroutine.create(function()
          wait(clickSound.TimeLength)
          Audio:Destroy()
     end))
     wait(0.025)
end

My best way to play sounds repeatedly was this.
maybe there’s another good way to do it, but here’s my script.
Cloning clickSound and playing them, destroying audio after it was ended.
(However, you can use Audio.Audio event provided by @me_isidoit.
I was curious if Audio.Ended works even 0.025 seconds of waiting.)