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

How do i stop the music?

Asked by
sad_eyez 162
8 years ago

I need to know what to add to stop the music when clicked again

local S = Instance.new("Sound", script.Parent) if S.IsPlaying == true then S:Stop() end S.Looped = true S.SoundId = "rbxassetid://145224950" S:Play()

end)

0
Can you please explain what you are trying to do with this script? KingLoneCat 2642 — 8y

2 answers

Log in to vote
0
Answered by 8 years ago

If you're asking how to make a brick play a sound when clicked this would be how to do that,

script.Parent.MouseClick:connect(function()
   local S = script.Parent:FindFirstChild('Sound')
   if  S then
       if S.IsPlaying == true 
         S:Stop()
      else
         S:Play()
      end    
   else
      local S = Instance.new('Sound', script.Parent)
      S.SoundId = "rbxassetid://145224950"
      S:Play()
   end
end)

Yeah... I fixed the error I made. This should work now though.

0
Indentation is annoying /: User#11440 120 — 8y
0
i figured it out guys, thanks for the help though sad_eyez 162 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

@ wfvj014, that'd be a waste. If you use WaitForChild, the script will wait for it to exist. You ran an else which would then create the sound if it's not existing but that won't work using WaitForChild due to the script waiting for the sound to exist.

local SoundId = 145224950

script.Parent.MouseClick:connect(function()
    if  script.Parent:FindFirstChild("Sound") ~= nil then
        script.Parent.SoundId = "rbxassetid://"..SoundId
        if script.Parent.Sound.IsPlaying == true 
            script.Parent.Sound:Stop()
    else
        script.Parent.Sound:Play()
    end

    else
    local S = Instance.new('Sound', script.Parent)
    S.SoundId = "rbxassetid://"..SoundId 
    S.Name = SoundId
    S:Play()
end
end)

Answer this question