I was wondering if you guys could help me on making a part play or stop its music when a player clicks it. Similar to when you click the potato in Bus Stop Simulator. Btw I added a clicking sound when you click the part.
local clickdetector = script.Parent:WaitForChild("ClickDetector") clickdetector.MouseClick:Connect(function() game.Workspace.BOOM.Sound:Stop() game.StarterPlayer.Humanoid.Sound:Stop() local clickdetector = script.Parent:WaitForChild("ClickDetector") end) wait(1) clickdetector.MouseClick:Connect(function() game.Workspace.BOOM.Sound:Stop() game.StarterPlayer.Humanoid.Sound:Play() end)
This is all I can come up with, sadly. Please tell me what I'm doing wrong, It would really help! And yes the part which music is coming off from it is called 'BOOM'.
Ok, so first off, this can be solved through a single function and the use of an 'if' statement.
What you're currently doing is connecting a function to the click detector's MouseClick event, and then connecting another, separate function to the same event. This means that both functions will run every time you click on the object. They will both stop the sound under the Humanoid, but one will play the sound BOOM and the other will stop it, so I really have no idea what actually happens when you run this.
Also, I'm not sure why you're making this toggle a sound in the StarterPlayer.
The code below is a suggestion on how you could solve this. I'm assuming that you wish to turn off a sound in the Humanoid of the player's current character based on your description, so I changed that line as well, but if that's really not what you wanted you can change it back.
local clickdetector = script.Parent:WaitForChild("ClickDetector") clickdetector.MouseClick:Connect(function() if workspace["BOOM"].Sound.isPlaying == true then workspace["BOOM"].Sound:Stop() game.Players.LocalPlayer.Character.Humanoid.Sound:Stop() else workspace["BOOM"].Sound:Play() game.Players.LocalPlayer.Character.Humanoid.Sound:Play() end end)