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

Script won't play sound the way i want it to. Could someone check my script?

Asked by 3 years ago

I'm trying to make a local script, where when you press a text button, it plays a sound (looped) and if you click the text button again it will stop the sound

but if the sound is playing and you press a different text button, it will stop sound1 and play sound2

and again if textbutton2 is pressed, it will stop the sound that is playing. and if you press text button1 it will stop sound 2 and play sound 1, and so forth

i was planning on adding more Sounds and textbuttons so i planned on making the for_, value, so it checks if any of the audios are running. instead of using sound 2, so it doesn't get messy in the future

but my script doesn't seem to be working help would be nice. you don't have to help if it looks like a struggle

script

local player = game.Players.LocalPlayer local character = player.Character if not character or not character.Parent then character = player.CharacterAdded:wait() end wait()

local MainGui = script.Parent local Textbutton1 = MainGui.ScrollingFrame.Dance1 local Textbutton2 = MainGui.ScrollingFrame.Dance2 wait()

---First Dance Textbutton1.MouseButton1Up:Connect(function(Touched)

if Touched then do 
        for _, value in ipairs(character.Head.SongFolder:GetChildren()) do
            if value:IsA("Sound") then do
                    if value.Playing == false then do --if you click on the first button and none of the sounds are playing,
                            character.Head.SongFolder.Sound1.Playing = true
                            print("Sound playing1")---then it will play sound 1

                            return end
                        end
                    end 
                end 
            end 
        end         
    end
wait()
if Touched then do 
        for _, value in ipairs(character.Head.SongFolder:GetChildren()) do
            if value:IsA("Sound") then do
                    if character.Head.SongFolder.Sound1.Playing == true then do
                            value:Stop() -- if sound 1 is playing and you click on it, it will end all sounds
                            print("Sound playing2")
                            return end
                        end
                    end 
                end 
            end 
        end         
    end
wait()
if Touched then do 
    for _, value in ipairs(character.Head.SongFolder:GetChildren()) do
        if value:IsA("Sound") then do
                if value.Playing == true then do
                        character.Head.SongFolder.Sound1.Playing = true
                        print("Sound playing3")

                        return end

                    end
                end 
            end 
        end 
    end             
end 

end)

I thought i might ask others instead of just giving up. I've been on this for many hours.

0
Before I offer my potential solution, I want to gain a better understanding of your goal. You want to be able to toggle every music track on/off by clicking on it, and when a track gets toggled on, all other tracks get silenced? sifn 70 — 3y
0
Yes! You press a button and it turns Music on, if you press the same one again it will turn off. If you press another button, it will turn the others off and etc.. superbubba2020 6 — 3y
0
man, are you trolling me? You got my hopes up. superbubba2020 6 — 3y
0
At least respond superbubba2020 6 — 3y

Answer this question