I’m making a script that reveals a message one character at a time and plays a typewriter sound at a slightly randomized pitch with each character revealed.
This is the script:
local TextLabel = script.Parent
local Button = game.Players.LocalPlayer.PlayerGui:WaitForChild("ScreenGui").OptionYes
local message = "So, this is the place Joey told me about..." -- put your full message here
local message2 = "This old building is the perfect place to host something of value." -- put your full message here
local message3 = "Now it's time to open these rusted doors and hopefully find something worth my time." -- put your full message here
local message4 = "What is this place?..." -- put your full message here
local message5 = "..." -- put your full message here
local message6 = "The door is gone." -- put your full message here
local message7 = "I need to find some way out of here." -- put your full message here
local Audio = game.ReplicatedStorage.TypeWriter
local function StartNewGame()
task.wait(5)
for i = 1, #message, 1 do
local CloneAudio = Audio:Clone()
local PS = CloneAudio:FindFirstChildOfClass("PitchShiftSoundEffect")
PS.Octave = math.random(95, 105)/100
CloneAudio.Parent = game.SoundService
TextLabel.Text = string.sub(message, 1, i)
CloneAudio:Play()
CloneAudio.Ended:Connect(function()
CloneAudio:Destroy()
end)
task.wait(0.08)
end
task.wait(3)
for i = 1, #message2, 1 do
local CloneAudio = Audio:Clone()
local PS = CloneAudio:FindFirstChildOfClass("PitchShiftSoundEffect")
PS.Octave = math.random(95, 105)/100
CloneAudio.Parent = game.SoundService
TextLabel.Text = string.sub(message2, 1, i)
CloneAudio:Play()
CloneAudio.Ended:Connect(function()
CloneAudio:Destroy()
end)
task.wait(0.08)
end
task.wait(3)
for i = 1, #message3, 1 do
local CloneAudio = Audio:Clone()
local PS = CloneAudio:FindFirstChildOfClass("PitchShiftSoundEffect")
PS.Octave = math.random(95, 105)/100
CloneAudio.Parent = game.SoundService
TextLabel.Text = string.sub(message3, 1, i)
CloneAudio:Play()
CloneAudio.Ended:Connect(function()
CloneAudio:Destroy()
end)
task.wait(0.08)
end
task.wait(3)
TextLabel.Visible = false
task.wait(8)
TextLabel.Visible = true
for i = 1, #message4, 1 do
local CloneAudio = Audio:Clone()
local PS = CloneAudio:FindFirstChildOfClass("PitchShiftSoundEffect")
PS.Octave = math.random(95, 105)/100
CloneAudio.Parent = game.SoundService
TextLabel.Text = string.sub(message4, 1, i)
CloneAudio:Play()
CloneAudio.Ended:Connect(function()
CloneAudio:Destroy()
end)
task.wait(0.08)
end
task.wait(3)
for i = 1, #message5, 1 do
local CloneAudio = Audio:Clone()
local PS = CloneAudio:FindFirstChildOfClass("PitchShiftSoundEffect")
PS.Octave = math.random(95, 105)/100
CloneAudio.Parent = game.SoundService
TextLabel.Text = string.sub(message5, 1, i)
CloneAudio:Play()
CloneAudio.Ended:Connect(function()
CloneAudio:Destroy()
end)
task.wait(1)
end
task.wait(3)
for i = 1, #message6, 1 do
local CloneAudio = Audio:Clone()
local PS = CloneAudio:FindFirstChildOfClass("PitchShiftSoundEffect")
PS.Octave = math.random(95, 105)/100
CloneAudio.Parent = game.SoundService
TextLabel.Text = string.sub(message6, 1, i)
CloneAudio:Play()
CloneAudio.Ended:Connect(function()
CloneAudio:Destroy()
end)
task.wait(0.08)
end
task.wait(3)
for i = 1, #message7, 1 do
local CloneAudio = Audio:Clone()
local PS = CloneAudio:FindFirstChildOfClass("PitchShiftSoundEffect")
PS.Octave = math.random(95, 105)/100
CloneAudio.Parent = game.SoundService
TextLabel.Text = string.sub(message7, 1, i)
CloneAudio:Play()
CloneAudio.Ended:Connect(function()
CloneAudio:Destroy()
end)
task.wait(0.08)
end
task.wait(3)
TextLabel.Visible = false
end
Button.MouseButton1Click:Connect(StartNewGame)
If I change local Button = game.Players.LocalPlayer.PlayerGui:WaitForChild("ScreenGui").OptionYes
to local Button = game.Players.LocalPlayer.PlayerGui.ScreenGui.OptionYes
it outputs an error, but works, at least in Roblox Studio. When I play the game on Roblox, the audio bugs and plays twice at once when it shouldn’t. Seriously the amount of differences between Roblox and Roblox Studio can make it so difficult to playtest a game.
Is there any way I can stop the audio from playing twice?