Cant play a sound multiple times in a for loop

Im making a simple type write effect but I ran into a problem, I want to play a sound after each letter has been displayed but the script only plays it once despite it being in the for loop, Any help is appreciated.

Script:

	local GUI = game.ReplicatedStorage.Dialouge:Clone()
	GUI.Parent = Player.PlayerGui
	local MFrame = GUI.MFrame
	local TextW = MFrame.TextWraper
	local Text = TextW.Text
	
	local Sound = Instance.new("Sound")
	Sound.Parent = GUI
	Sound.SoundId = "rbxassetid://"..Table['Sound']
	local TextToPrompt = Table["PromptText"]
	for i = 1, #TextToPrompt do
		Text.Text = string.sub(TextToPrompt, 1, i)
		Sound:Play()
		print("SoundPlayed")
		wait()
	end

Here’s the sound:
https://www.roblox.com/library/358280695/sans-dialogue-sound-effect?Category=Audio&SortType=Relevance&SortAggregation=AllTime&SearchKeyword=Dialogue+sound&CreatorId=0&Page=1&Position=2&SearchId=6b5e8501-4e06-4afe-8d6d-fc04efcbcb84

3 Likes

Instead of

Sound:Play()
print("SoundPlayed")
wait()

Use

Sound.Playing = true
print("SoundPlayed")
wait()
Sound.Playing = false

Try this and tell me if it works or if there is are bug/errors

1 Like

Same problem it just plays it once

1 Like

1 Like

Just as a test try setting the wait to be 1 second and see what happens
If it works then the wait is too short* and the sound is not done playing

Edit just testing with the sound it works fine for me

1 Like

Nope still plays only 1 time

If you want to see the full script ill send you it

1 Like

Could i see it because its working fine for me

function Dialouge.MakeDialouge(Settings, Player)
	local Table = Settings["Prompt"]
	
	if Player.PlayerGui:FindFirstChild("Dialouge") then
		Player.PlayerGui.Dialouge:Destroy()
	end
	
	local GUI = game.ReplicatedStorage.Dialouge:Clone()
	GUI.Parent = Player.PlayerGui
	local MFrame = GUI.MFrame
	local TextW = MFrame.TextWraper
	local Text = TextW.Text
	
	local Option1 = MFrame.Options.OP1
	local Option2 = MFrame.Options.OP2
	local Option3 = MFrame.Options.OP3
	
	local Sound = Instance.new("Sound")
	Sound.Parent = GUI
	Sound.SoundId = "rbxassetid://"..Table['Sound']
	local TextToPrompt = Table["PromptText"]
	for i = 1, #TextToPrompt do
		Text.Text = string.sub(TextToPrompt, 1, i)
		Sound.Playing = true
		print("SoundPlayed")
		wait(1)
		Sound.Playing = false
	end
	
	if Table["Option1"] then
		Option1.Visible = true
		Option1.Text = Table["Option1"].Choice
	end

	if Table["Option2"] then
		Option2.Visible = true
		Option2.Text = Table["Option2"].Choice
	end
	
	if Table["Option3"] then
		Option3.Visible = true
		Option3.Text = Table["Option3"].Choice
	end
		
	
	Option1.MouseButton1Click:Connect(function()
		Actions[Table["Option1"].Action](Table["Option1"].Data, Player)
	end)
	Option2.MouseButton1Click:Connect(function()
		Actions[Table["Option2"].Action](Table["Option2"].Data, Player)
	end)
	
	Option3.MouseButton1Click:Connect(function()
		Actions[Table["Option3"].Action](Table["Option3"].Data, Player)
	end)
end

So is

local TextToPrompt = Table["PromptText"]

Another table?
Using #TextToPrompt can only be used on tables

		local Settings = {
			Prompt = {
				PromptText = "Hello there do you want to buy something?",
				Sound = "358280695",
				-- First Option
				Option1 = {
					Choice = "Mhm.",
					Action = "MakeDialouge",
					Data = {
						Prompt = {
							PromptText = "Oh you're still going just why?",
							Sound = "358280695",
							Option1 = {
								Choice = "Ok im done lol",
								Action = "CloseDialouge",
								Data = false
						},
					}
				}
			},

			-- Second Option
			Option2 = {
				Choice = "Nevermind.",
				Action = "CloseDialouge",
				Data = false
			},

			Option3 = {
				Choice = "Goodbye.",
				Action = "CloseDialouge",
				Data = false,
			}
		}
	}
1 Like

The type writer effects works fine its just the sound doesnt play

1 Like

Could i see a screenshot of the sounds properties?
I made a little test script and it works fine

1 Like

Hmm interesting it seems this is because it in a GUI for some reason it doesn’t work inside a GUI try placing it in Sound Service or Workspace
Also whenever i put my script inside a GUI the sound doesn’t even play once so this might be unrelated

No still plays once, Should i just keep creating sounds then removing them or thats not good for the server

Well i don’t see why it wouldn’t be good for the server i still don’t recommend it as your solution should work but i have a couple questions now
This is a Local Script right?
The sound is located inside of StarterGui?(technically Player Gui)

The sound is located in the PlayerGui yes, but im not using a LocalScript im using a Module script

But the Module Script is being required by a local script right?

No, by a server script inside a clickdetector

1 Like

Okay I think the problem was the Sound was still loading so it wasnt able to play multiple times maybe?, instead I made a sound and placed it in the StarterCharacterScript then changed its sound id based on the Table that the script sent and it now works.

	Player.Character.DialougeSound.SoundId = "rbxassetid://"..Table["Sound"]
	local TextToPrompt = Table["PromptText"]
	for i = 1, #TextToPrompt do
		Text.Text = string.sub(TextToPrompt, 1, i)
		Player.Character.DialougeSound:Play()
		print("SoundPlayed")
		wait()
	end
2 Likes