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
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
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
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)
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