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

How can I scipt a brick with Clickdetector that can turn on/off the music?

Hello, I want to make a brick with ClickDetector that can play the id '2315428899' only if turned on and stop playing when a player turn it off. I'm new at scripting, can someone help me?

4 comments

0

please someone?

0

this isn't technically a request...fine

0

.

1 answer

Here is the hierarchy I recommend you go with:

  • A part is the parent of a ClickDetector, a Sound instance and a script.

Example script:

local sound = script.Parent.Sound
local bool = true
script.Parent.ClickDetector.MouseClick:Connect(function()
	if bool == false then
		sound:Pause() -- Music can be resumed
		bool = true
	end
	if bool == true then
		if not sound.Played then
			sound:Play()
			bool = false
		elseif sound.Played then
			sound:Resume()
			bool = false
		end
	end
end)

This script plays the sound then checks to see if the sound was played before resuming it. It also pauses it if the debounce is false.

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