Sound works in studio but not real game

The title says it all, my sound is working in studio but when you play the real game it doesn’t play.

I tried printing if it is playing and it prints true.

Here is my code (Only look at sound bit)

local StarterGui = game:GetService("StarterGui")
local WarheadScreen = StarterGui.WarheadScreen
local WarheadFrame = WarheadScreen.WarheadFrame

local TouchedPart = script.Parent.Keycard.TouchedPart

local CountdownGui = script.Parent.Countdown
local Screen = CountdownGui.Screen
local WarheadStatus = Screen.Status

local Announcement = workspace.Announcement
local Siren = workspace.Siren
local BackgroundMusic = workspace.BackgroundMusic

local Activated = script.Activated

local Clearance = {
	["Omni"] = true;
	["L5"] = false;
	["L4"] = false;
	["L3"] = false;
	["L2"] = false;
	["L1"] = false;
}

TouchedPart.Touched:Connect(function(Hit)
	if (Hit.Name == "Handle" and Clearance[Hit.Parent.Name]) and not Activated.Value then
		Activated.Value = true
		
		spawn(function()
			WarheadStatus.TextColor3 = Color3.fromRGB(255, 170, 0)
			
			local function ConvertNumbers(Seconds)
				local Minutes = Seconds / 60
				local Hours = Seconds / 3600
				
				return string.format("%02d:%02d:%02d", Hours, Minutes % 60, Seconds % 60)
			end
			
			for i = 210, 0, -1 do	
				WarheadStatus.Text = ConvertNumbers(i)
				wait(1)
			end
		end)
		

		for _, light in pairs(workspace:GetDescendants()) do
			if light:IsA("PointLight") then
				light.Color = Color3.fromRGB(255, 0, 0)
				light.Brightness = 3
				light.Range = 12

				light.Parent.Parent.Light1.Color = Color3.fromRGB(255, 0, 0)
				light.Parent.Parent.Light2.Color = Color3.fromRGB(255, 0, 0)
			end
		end
		

		Announcement:Play()
		wait(1)
		Siren:Play()
		wait(Announcement.TimeLength + 0.5)
		BackgroundMusic:Play()
		
		wait(BackgroundMusic.TimeLength)
		
		Siren:Play()
		
		for i = BackgroundMusic.Volume, 0, -0.05 do
			BackgroundMusic.Volume = i
			wait()
			
			if BackgroundMusic.Volume == 0 then
				BackgroundMusic:Stop()
			end
		end
		
		for i = 1, 0, 0.05 do
			WarheadFrame.BackgroundTransparency = i
		end
	end
end)

It appears the problem is that it’s only server-side.
When you play test a game you act as both the server and the client. And when you actually play it you only act as the client.
You should place the sounds inside of the PlayerGui instead, this will also lessen the load on the server.

Wait what?

I want the whole server to hear the music aswell as the client. Mind explaining your method to me?

1 Like

Gui’s placed inside the StarterGui service are distributed to every single player.

When someone with the clearance touches the part you can make the sound play on all Gui’s by creating a FireAllClients event.

Make sure your GUI has reset on respawn off, otherwise the sound will break when the player dies.

I just discovered something weird. The audio plays fine on mobile.

Also couldn’t I put it in replicatedstorage?

Why don’t you put it inside SoundService? I’m pretty sure SoundService replicates it correctly.

I tried that, it didn’t work…

After working out some solutions, I believe that this may be a Studio Bug. Sounds don’t play if there is any delay at all. If you don’t find any solutions to this problem within the day, I would recommend reporting it as a bug at #bug-reports:studio-bugs

The primary reason this is most likely a bug is that simply doing:

wait(5)
Sound:Play()

Doesn’t work as intended.

1 Like

So your saying that if there is a delay they don’t work?

Yes, sorry for the late reply.

I was testing your problem in Roblox Studio and found that whenever there is a delay prior to a sound playing it doesn’t work.

However,

Perhaps you could take a sound from ServerStorage and Instance:Clone() it to the Workspace then play it as soon as it is made?
Then when the Sound.TimeLength has finished you can Instance:Destroy() the sound.

2 Likes