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

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

Asked by 5 years ago

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?

0
please someone? Gabrix23 6 — 5y
0
this isn't technically a request...fine DeceptiveCaster 3761 — 5y
0
. BuzzKillGT 33 — 5y

Closed as Not Constructive by DeceptiveCaster and User#24403

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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.

Ad