This is the current gui script to just press the play button, pretty simple, however I don’t know how to add a music ID to it. How would I do that?
Just
-
Insert a Sound in your Explorer
-
Set the
SoundID
property to the ID of the sound (Located on the browser link/looking up Audios in your toolbox by right clicking & copying the ID) -
Locate where you inserted the Sound, then Play/Pause it upon activation with your
MouseButton1Click
Event
Right I’ve done step 1 & 2 except I don’t know what I need to write in the script I don’t know how to do step 3.
Depending on where you put the Sound:
local Sound = script.Parent.SoundLocation
script.Parent.MouseButton1Click:Connect(function()
if script.Parent.Parent.Visible = true then
script.Parent.Parent.Visible = false
Sound:Resume()
else
script.Parent.Parent.Visible = true
Sound:Pause()
end
end)
Just replace that script with the one I sent earlier, should still be the same thing hopefully (Set the ID in the Explorer’s Properties)
Ok, I just tried that and it broke my place button and the music didn’t play.
Really? Can you add print()
statements to detect where it stopped playing/working?
Well I think deleting the script as you said just removed the remove menu part of the script but the music just didn’t play.
--// Variables //--
local Sound = --// Location
local Button = script.Parent
--// Functions //--
Button.MouseButton1Click:Connect(function()
Sound:Play()
end)
This script is so that when you click the button, the sound starts playing.
Also, here’s a bit of help.
I put the sound id after sound, what else do I need to fill in? (I’m a bit new to scripting)
No, just add a Sound Object, and check the properties. The sound object has different properties to set-up. I will give you a picture, the red mark is where you must insert the sound ID.
But, anyway, explain what you are trying to do and the structure of your objects.
I know the sound ID and thats what I put after "local sound = "
I’m trying to add music to my main menu and make the music stop after pressing “Play”
Try this:
local Sound = Instance.new("Sound",script)
Sound.SoundId = "rbxassetid://" .. 0
script.Parent.MouseButton1Click:Connect(function()
script.Parent.Parent.Visible = false
Sound:Play()
end)
Replace 0 with the sound id.
Well, that played the sound after I click play, I’m trying to make the sound play until you get off the menu.
local Sound = Instance.new("Sound",script)
Sound.SoundId = "rbxassetid://" .. 0
script.Parent.MouseButton1Click:Connect(function()
script.Parent.Parent.Visible = false
Sound:Play()
end)
local ExitButtom = script.Parent.ExitButtom
ExitButtom.MouseButton1Click:Connect(function()
Sound:Stop()
end)
Replace this part with the exit button location:
script.Parent.ExitButtom
Alright! I just made this, I tested and worked. I will show you my objects structure.
--// Variables //--
local Button = script.Parent
local Sound = script.Parent.Parent:WaitForChild("Sound")
local inProgress = false
local isPaused = false
Sound.SoundId = "rbxassetid://" .. 1376107746
Button.MouseButton1Click:Connect(function()
if inProgress == false and isPaused == false then
local Success, Error = pcall(function()
Sound:Play()
end)
if not Error then
print("Success.")
inProgress = true
else
if Error then
print("Sound Error: ", Error)
inProgress = false
end
end
elseif inProgress == true then
Sound:Pause()
isPaused = true
inProgress = false
elseif inProgress == false and isPaused == true then
Sound:Resume()
inProgress = true
isPaused = false
end
end)