My game typewriting system keeps playing audio even after the typewriting is done?

So, I’ve just came across this (as I’ve only now needed to use it) but whenever I play an audio inside of my typewrite for loop the audio keeps playing even after the text has finished being displayed?
Any help would be greatly appreciated, (i know I don’t need the time positions I was just testing out ways to fix this.)

local function typewrite(object,text,length)
	object.MaxVisibleGraphemes = 0

	for i = 1,#text,1 do
		script.Parent.Parent.Audio.TimePosition = 0
		script.Parent.Parent.Audio:Play()
		object.Text = text
		object.MaxVisibleGraphemes = i
		task.wait(length)
	end
	script.Parent.Parent.Audio.TimePosition = 0
	script.Parent.Parent.Audio:Stop()
end
2 Likes

Try putting a print statement when stoping the audio maybe to see if it’s printing?

1 Like
local function typewrite(object, text, length)
	object.MaxVisibleGraphemes = 0
	object.Text = text
	
	if script.Parent.Parent.Audio.Looped then
		script.Parent.Parent.Audio.Looped = false
	end

	for i = 1, #text, 1 do
		object.MaxVisibleGraphemes = i
		
		script.Parent.Parent.Audio.TimePosition = 0
		script.Parent.Parent.Audio:Play()
		
		task.wait(length)
		
		script.Parent.Parent.Audio:Stop()
	end
	
	if script.Parent.Parent.Audio.IsPlaying then
		script.Parent.Parent.Audio:Stop()
	end
	
	script.Parent.Parent.Audio.TimePosition = 0
end
1 Like

Hmm, for some reason It still keeps repeating the audio. I will try using print statements.

Maybe try setting the Volume to zero after the for loop is complete?

no that doesnt seem to work either

Are there any scripts that execute the function multiple times or other scripts that use that audio?

There is another script that uses the typewriting with the same audio but it runs at different times.

are you sure the audio isnt looped?

1 Like

yes. i did test it with looped to see if it fixes the issue but it didn’t so I turned off the loop.

Is the script you showed on the first post a Server Script?

no its on a localscript for a gui

is this function being fired multiple times?

You didn’t tick the Playing box or Looped Box?

Did u put the print statement after or 1 line above when u stop the audio?
If it printed multiple times then you are firing multiple functions and that maybe the problem