I’ve made a system where when you press a button it mutes the sound, but since the sound is looped so It’ll play once the second loop starts. I don’t want this to happen. Let me know if you need any more information.
The script:
local part = game.Workspace.SoundRegions2.Part
local part2 = game.Workspace.SoundRegions2.Part2
local part3 = game.Workspace.SoundRegions2.Part3
local part4 = game.Workspace.SoundRegions2.Part4
local part5 = game.Workspace.SoundRegions2.Part5
local part6 = game.Workspace.SoundRegions2.Part6
script.Parent.MouseButton1Click:Connect(function()
if part.Volume == 0 or part2.Volume == 0 or part3.Volume == 0 or part4.Volume == 0 or part5.Volume == 0 or part6.Volume == 0 then
part.Volume = 0.5
part2.Volume = 0.5
part3.Volume = 0.5
part4.Volume = 0.5
part5.Volume = 0.5
part6.Volume = 0.5
script.Parent.Image = "http://www.roblox.com/asset/?id=5989509343"
else
part.Volume = 0
part2.Volume = 0
part3.Volume = 0
part4.Volume = 0
part5.Volume = 0
part6.Volume = 0
script.Parent.Image = "http://www.roblox.com/asset/?id=5990231900"
end
end)
Thanks, I’ll take a look at it. Basically, I’ve made a Music On/Off button it works however when the song repeats (because the song is looped) it’ll start to play again.
How would I convert them into tables? If you don’t mind can you show me an example or explain? I’ve read the actual tables documentation but I don’t know how I’d apply it to this situation specifically.
So, have a table full of sound ids. And also have an index variable. Every time the sound end event fires, increase the index by one and set the sound Id to the one in the table. Repeat this until you are at the end. However, you can indeed pause the sound and unpause it without breaking the system. I am on my iPad,if I were on my pc, I would have just given you the fully functional code. Plus, my mom’s calling for dinner
I’ve changed up my code a bit, still not working though. Here’s the new code I came up with, but still not working like I said. (bump)
local status = script.Value
local on = status.Value == "On"
local off = status.Value == "Off"
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
if on == "On" then
print("On!")
local soundregions = game.Workspace.SoundRegions2:GetChildren()
for i,v in pairs (soundregions) do
v.Volume = 0
end
status.Value = "Off"
elseif on == "Off" then
print("Off!")
local soundregions = game.Workspace.SoundRegions2:GetChildren()
for i,v in pairs (soundregions) do
v.Volume = 0.5
end
status.Value = "On"
end
end)
if I am undestanding you right this should stop the sounds where they are then restart them after you unmute
local status = script.Value
local on = status.Value == "On"
local off = status.Value == "Off"
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
if on == "On" then
print("On!")
local soundregions = game.Workspace.SoundRegions2:GetChildren()
for i,v in pairs (soundregions) do
v.Volume = 0
v.PlaybackSpeed = 0 -- will make the sound stop playing but stay in play status(Pauses it)
end
on = 'Off'
status.Value = "Off"
elseif on == "Off" then
print("Off!")
local soundregions = game.Workspace.SoundRegions2:GetChildren()
for i,v in pairs (soundregions) do
v.Volume = 0.5
v.PlaybackSpeed = 1 -- unpause the sound
end
on = 'On'
status.Value = "On"
end
end)
oh nice work on changing this over to a table of objects and cleaning up the code
That didn’t work so I’ll re-explain. Basically I’m trying to make it so when you press the button the sound mutes and when you press it again it unmutes.
ok i think the problem you are having here is a roblox BUG…
it seems for some unknown reason if a sound is set to looping and also set to playing it will double play when you hit play in studio atleast where i am testing in the ui
so i think to fix this you need to uncheck Playing on all the sounds then just fire play on them when the script starts
I will edit the script above to have the initial for loop to make them play – also you can use a ipairs loop if you wanted them to be changed in order