Typewrite Talk Sound Producing Crackling Audio

I have a script that “typewrites” text in a dialogue box, and I have a sound play for every letter except if its a space. I noticed that because of that, the audio that is played back to back has this crackling/popping sound. Is there any way to fix this? The audio itself is not the issue, the beginning and end of the audio are faded in and out, so it should not produce popping sounds.

local function typewrite(object, text, length)
	local stoptext = false
	ReplicatedStorage.StoryEvents.DialogueEnd.OnClientEvent:Connect(function()
		stoptext = true
	end)
	for i = 1, #text, 1 do
		object.Text = string.sub(text,1,i)
		
		if string.sub(text,i,i) ~= " " then
			if gui.TalkSound.IsPlaying then
				gui.TalkSound:Stop()
			end
			gui.TalkSound:Play() -- where talksound plays
		end
		
		if stoptext == true then
			break -- will not continue if interrupted to prevent text glitching
		end
		
		wait(length) -- time between letters
	end
end

Try playing with volume instead of :Stop

When there is a space, make it volume 0, when its back to normal make it volume 5 or something and when the typing is finished make it :Stop

correct me if this is not the issue

I had the :Stop there so the sound could repeat smoothly. Sometimes without using the Stop function, the sound will just not play. adding that helped. But for the sake of trying it I’ll try it out real quick just to see.

1 Like

Make it wait? maybe the audio is overplaying

task.wait(0.2)

This usually means that you’re playing the ‘Sound’ object too frequently.
if not Sound.IsPlaying then Sound:Play() end

1 Like