Typewriting sound not working using For loops and GetPropertyChangedSignal (AnimateUI module)

  1. I want to make a sound play each time a letter is added, but my attempts at it won’t work.

  2. But the issue is that my For loops won’t work, and I find it kinda hard to get the code from other topics in the DevForum into the AnimateUI code. I also tried to do GetPropertyChangedSignal(“Text”), but that also didn’t work. The sound I’m using is 0.134 seconds long, and I’m not sure if that’s the problem.

This is the part of code I use. It’s the AnimateUI module that Roblox made and put on the DevHub, and I changed it a little. I’m new to strings and all that, so I don’t have any idea on how to go about this.

Sorry if any of this is confusing, if you need me to explain something you didn’t understand feel free to reply :smiley:

	if guiObject.Parent.Visible == false then -- Checks if the Dialogue frame isn't visible; It turns invisible after Dialogue is finished
		guiObject.Parent.Visible = true
		guiObject.Visible = true
		guiObject.AutoLocalize = false
		local displayText = text

		-- Translate text if possible
		if translator then
			displayText = translator:Translate(guiObject, text)
		end

		-- Replace line break tags so grapheme loop will not miss those characters
		displayText = displayText:gsub("<br%s*/>", "\n")
		displayText:gsub("<[^<>]->", "")

		if string.gmatch(text, ".") then
			wait(1)
		end

                  for i = 1,#text do -- Sound play part
			guiObject.Parent.Parent.Text:Play()
			guiObject.Parent.Parent.Text.Ended:Wait()
		end

		-- Set translated/modified text on parent
		guiObject.Text = displayText

		guiObject.Parent:FindFirstChild("ImageLabel").Image = "http://www.roblox.com/asset/?id="..ID

		local index = 0
		for first, last in utf8.graphemes(displayText) do
			index = index + 1
			guiObject.MaxVisibleGraphemes = index
			wait(delayBetweenChars)
		end
		wait(2)
		guiObject.Text = "..."
		guiObject.Parent.Visible = false
	end
end
for i = 1,#text do -- Sound play part
			guiObject.Parent.Parent.Text:Play()
			guiObject.Parent.Parent.Text.Ended:Wait()
		end

Parent the sound to workspace, and directly access it through this:

for i = 1,#text do -- Sound play part
			workspace.Text:Play()
			workspace.Text.Ended:Wait()
		end

This script will need to be a LocalScript! (So the sound can get played for just the individual client, and not for everyone.) :smiley:

yo tysm!! but whats the reason on why it wouldn’t work in the gui? i had the sound in there, and i know it was the right explorer path

Apologies for the late reply! The reason why is because in PlayerGui, you can’t play the audio- I guess that’s because it’s on the client, and you have to do it from a server “folder”, but play it from the client.

Of course that’s just a guess, but that’s most likely why! :smiley:

1 Like