Typewriter effect sound playing wrong

Hello, any idea why the sound is only playing when the text has finished loading?

	local function TypeWriterEffect(object, text)
		for i = 1, #text, 1 do
			task.spawn(function()
				TypeSound:Play()
			end)
			object.Text = string.sub(text, 1, i)
			wait(0.05)
		end
	end

How long is the audio you are trying to play?

Also, you might need to load it to ensure it’s ready to play.

Your sound probably has blank space in the first 0.1 or so seconds.

Also, here’s a rewritten version of your code that should make things more efficient.

function TypeWriterEffect(label: TextLabel, text: string)
	-- The ,1 is unncessesary since that will be the default forever.
	for i = 1, #text do
		TypeSound:Play()

		label.Text = string.sub(text, 1, i)

		-- The default wait method is extremely unstable and inaccurate. Use task.wait().
		task.wait(0.05)
	end
end

This is because (like the docs says) every time you call :Play() the sounds starts back from 0 so your audio did not have time to play properly before it is again reset to 0 by the next iteration of the loop.
You can prevent this by cloning your sound object.

	local function TypeWriterEffect(object, text)
		for i = 1, #text, 1 do
			task.spawn(function()
				local newSound = TypeSound:Clone()
				newSound:Play()
				newSound.Ended:Wait()
				newSound:Destroy()
			end)
			object.Text = string.sub(text, 1, i)
			task.wait(0.05)
		end
	end

also to add onto your typewritter effect, if you have TextScaled enabled the text will jump around in size and not look that good it would be best to use the MaxVisibleGraphemes property. Also using # to get the length of a string can lead to errors for example print(#"😊") would be 4 because an emoji takes up 4 bytes. getting the amount of character using utf8.len would be more accurate.