Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to make a stereo cycling through sounds by clicking?

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

✓ Accepted answer

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)

3 comments

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?

0

I just sent you a friends req accept that and we will go into studio together

0

You don't use the sound id's you change the title of your sounds to Sound1 Sound2 Sound3 and so on

This discussion is preserved as it was. New answers, comments, and votes are closed.