Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

PA System - Works in studio but not in game?

Asked by 8 years ago

I am developing a PA system with a GUI that you can announce things with. It searches for audio that you define, and if it finds, it, it plays it. It works fine in studio, but in-game it all plays at once, instead of waiting. Here is the GUI directory: StarterGUI AnnouncmentGUI Frame Script Text Text2 Text3 Text4 Text5 Text6 Text7 TextButton Here is the PA Speaker Directory: PASpeaker [14 Audios, within 0.7-2.0 seconds. Volume: 0.3] [i.e. "lockout", "evacuate", "complex"]

Here is the GUI script:

script.Parent.TextButton.MouseButton1Click:connect(function()
     local PASpeaker ={}for i,v in pairs(workspace:GetChildren())do if v.Name=="PASpeaker" then table.insert(PASpeaker,v)end end
for i,PASpeaker in pairs(PASpeaker)do 
local sounds = PASpeaker:GetChildren()
PASpeaker.login:Play()
wait(PASpeaker.login.TimeLength + 0.1)
PASpeaker.login:Play()
wait(PASpeaker.login.TimeLength + 0.1)
PASpeaker.login:Play()
wait(PASpeaker.login.TimeLength + 0.1)
for i=1,#sounds do
if sounds[i].Name:lower() == script.Parent.Text.Text then
sounds[i]:Play()
wait(sounds[i].TimeLength)
end
end
for i=1,#sounds do
if sounds[i].Name:lower() == script.Parent.Text2.Text then
sounds[i]:Play()
wait(sounds[i].TimeLength)
end
end
for i=1,#sounds do
if sounds[i].Name:lower() == script.Parent.Text3.Text then
sounds[i]:Play()
wait(sounds[i].TimeLength)
end
end
for i=1,#sounds do
if sounds[i].Name:lower() == script.Parent.Text4.Text then
sounds[i]:Play()
wait(sounds[i].TimeLength)
end
end
for i=1,#sounds do
if sounds[i].Name:lower() == script.Parent.Text5.Text then
sounds[i]:Play()
wait(sounds[i].TimeLength)
end
end
for i=1,#sounds do
if sounds[i].Name:lower() == script.Parent.Text6.Text then
sounds[i]:Play()
wait(sounds[i].TimeLength)
end
end
for i=1,#sounds do
if sounds[i].Name:lower() == script.Parent.Text7.Text then
sounds[i]:Play()
wait(sounds[i].TimeLength)
end
end
end
end)

I am not sure why it is playing the desired audio all at once. Does anyone else know why this is happening in-game but not in studio?

3
If you're not using a Local Script, use one and see if it works. Else try changing wait(sounds[i].TimeLength) to sound.Ended:wait(). User#11440 120 — 8y
0
I did both of the things you said and it works now. Thanks! The_Sink 77 — 8y

Answer this question