Hi,
I did a script in button that play all sounds when button is clicked (and stop them) everything works but sounds don’t play help:
-- Script inside button in game.StarterGui.ScreenGui
local b = script.Parent
local Activated = false
b.MouseButton1Click:Connect(function()
local allSounds = game.StarterPlayer.SoundsFolder:GetChildren()
if Activated then
Activated = false
b.BackgroundColor3 = Color3.fromRGB(55, 177, 33)
b.Text = "PLAY ALL SOUNDS"
for _, v in pairs(allSounds) do
v:Stop()
end
else
Activated = true
b.BackgroundColor3 = Color3.fromRGB(200, 0, 0)
b.Text = "STOP"
for _, v in pairs(allSounds) do
v:Play()
end
end
end)
I think that this is a local script. Probably SoundsFolder is empty when the game is loading for a client. I would use repeat until loop to wait for certain number of children inside the folder before using GetChildren() function to get the folder’s content.
I quicly made a GUI with a button. I put a server script inside the button. The event somehow worked. There are other potential issues (the folder is empty, sounds got removed, volume is set to 0 and more)
I came up with more ideas. Make sure that you can play any sounds at all (outside the Roblox game) You can also try cloning the sounds and setting their parent to Workspace. Try using these pieces of code inside the script to find the reason for the issue: print(table.getn(allSounds)) -- expected output: a number highter than 0
for _, v in pairs(allSounds) do
print(v.TimeLength) -- expected output: a number highter than 0
end
I did a quick test and I found out that if a sound is an ancestor of StarterPlayer, the sound won’t play. I tested it by using a script and two indentical sounds in Workspace and StarterPlayer and the script didn’t print any errors:
wait(6)
print("Start")
workspace.Sound:Play() -- I heard this sound
wait(3)
print("Start")
game:GetService("StarterPlayer").Sound:Play() -- I did not hear this sound
I would recommend trying SoundService:PlayLocalSound(). This function plays a sound locally, regardless of where the sound is parented.
Your edited code:
local SoundService = game:GetService("SoundService")
local b = script.Parent
local Activated = false
b.MouseButton1Click:Connect(function()
local allSounds = game.StarterPlayer.SoundsFolder:GetChildren()
Activated = not Activated
if Activated then
b.BackgroundColor3 = Color3.fromRGB(200, 0, 0)
b.Text = "STOP"
for _, v in pairs(allSounds) do
SoundService:PlayLocalSound(v)
end
else
b.BackgroundColor3 = Color3.fromRGB(55, 177, 33)
b.Text = "PLAY ALL SOUNDS"
for _, v in pairs(allSounds) do
v:Stop()
end
end
end)
Edit: I made your activate set itself opposite each time as opposed to setting each time in the if/else bit. Makes no difference, but it’s slightly more efficient.
Are you sure the sounds aren’t two mono tracks affected by error 46? Recently Roblox has disabled these from playing due to the fact they were used for copyright bypassing.