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)
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.
@ 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)