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

How to make a stereo cycling through sounds by clicking?

Asked by 3 years ago

I'm trying to make a working stereo that cycles through a number of sounds when clicking on it. I've figured out how to make it play a sound once it's clicked but I can't figure out how to make it play a different sound when its clicked again.

This is what I have so far:

Stereo = script.Parent
Sound = Stereo.Sound

function onClicked()
Sound:Play()
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

1 answer

Log in to vote
0
Answered by
M9F 94
3 years ago
Edited 3 years ago

This should work. Please accept as answer. Tell me if you have any problems, I'm also sending you a friends req on roblox.

Stereo = script.Parent

Sound1 = Stereo.Sound1

local soundNum = 0 

function onClicked()
    local currenSound = game.workspace.Stereo
    if soundNum < 3 then ----- Change the number to your last sound
        soundNum = soundNum + 1
    else
        soundNum = 1
    end 
    local selectedSound = currenSound["Sound" .. soundNum]
    selectedSound:Play()
    print(soundNum)
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

0
Okay so let's say I have 3 sounds all named "Sound" with different SoundId's, where would I place those in the script? felonymartinez 12 — 3y
0
I just sent you a friends req accept that and we will go into studio together M9F 94 — 3y
0
You don't use the sound id's you change the title of your sounds to Sound1 Sound2 Sound3 and so on M9F 94 — 3y
Ad

Answer this question