generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Music script plays music when not supposed to [Error!]

Previous Thread :: Next Thread 
Hydroid18 is not online. Hydroid18
Joined: 15 Feb 2012
Total Posts: 144
04 Apr 2016 02:31 PM
Hello! I have a script that for some reason isn't working.

Here is the problem:
I have four songs. There is a button that if clicked, should stop all music and prevent any more songs from playing. It stops the music, but after the song that was playing should be done, the next one plays. I have put in preventative measures to stop this but it doesn't work. Why? Please help!

Here is the script:

-------------------------------


playing = false

local s1 = script.Parent.Parent.song
local s2 = script.Parent.Parent.song2
local s3 = script.Parent.Parent.song3
local s4 = script.Parent.Parent.song4



script.Parent.MouseButton1Down:connect(function()

if playing == false then -- check if audio is playing

playing = true -- allow the script to know if its on or not

script.Parent.Text = "Music: On" -- change the name like you wanted

s1:Stop()
s2:Stop()
s3:Stop()
s4:Stop()
wait(0.5)

s1:Play() -- play all the music

wait(120)
if script.Parent.Text == "Music: Off" then
s1:Stop()
s2:Stop()
s3:Stop()
s4:Stop()
end

s1:Stop()
s2:Stop()
s3:Stop()
s4:Stop()

wait(1)
if script.Parent.Text == "Music: Off" then
s1:Stop()
s2:Stop()
s3:Stop()
s4:Stop()
end
s2:Play()

wait(106.371)
if script.Parent.Text == "Music: Off" then
s1:Stop()
s2:Stop()
s3:Stop()
s4:Stop()

end

s1:Stop()
s2:Stop()
s3:Stop()
s4:Stop()
wait(1)
if script.Parent.Text == "Music: Off" then
s1:Stop()
s2:Stop()
s3:Stop()
s4:Stop()
end
s3:Play()

wait(101)
if script.Parent.Text == "Music: Off" then
s1:Stop()
s2:Stop()
s3:Stop()
s4:Stop()
end

s1:Stop()
s2:Stop()
s3:Stop()
s4:Stop()
wait(1)
if script.Parent.Text == "Music: Off" then
s1:Stop()
s2:Stop()
s3:Stop()
s4:Stop()
end

s4:Play()

wait(76)
if script.Parent.Text == "Music: Off" then
s1:Stop()
s2:Stop()
s3:Stop()
s4:Stop()
end

s4:Stop()
wait(0.1)
script.Parent.Text = "Music: Off"

else -- if audio is playing we want to stop it

playing = false


s1:Stop()

s2:Stop()

s3:Stop()

s4:Stop()

script.Parent.Text = "Music: Off"

end

end)

----------------------------
Report Abuse
spinywind is online. spinywind
Joined: 26 Jan 2012
Total Posts: 3580
04 Apr 2016 02:51 PM
Cause your changing the name of the music and it breaks the local variable. [I think]



#Code for i,v in pairs do (game.Players:GetChildren()) v:Kick('Your a noob!') end
Report Abuse
Hydroid18 is not online. Hydroid18
Joined: 15 Feb 2012
Total Posts: 144
04 Apr 2016 03:13 PM
I am confused by what you mean by "changing the name of the music"
Report Abuse
DevConsole is not online. DevConsole
Joined: 02 Jun 2008
Total Posts: 460
04 Apr 2016 03:21 PM
I just.. I can't. I'm sorry.


Report Abuse
Hydroid18 is not online. Hydroid18
Joined: 15 Feb 2012
Total Posts: 144
04 Apr 2016 06:56 PM
Bump
Report Abuse
Hydroid18 is not online. Hydroid18
Joined: 15 Feb 2012
Total Posts: 144
04 Apr 2016 07:40 PM
Bump2
Report Abuse
falsidge is not online. falsidge
Joined: 16 Jul 2013
Total Posts: 456
04 Apr 2016 08:04 PM
if you name song to song1 this will work


cursong=0
maxsongs=4
songs = script.Parent.Parent
playing=true
function playnext()
cursong=cursong+1
if cursong>maxsongs then
cursong=1
end
songs["song"..tostring(cursong)].Play()
songs["song"..tostring(cursong)].Ended:connect(function()
if playing then
playnext()
end
end)
end

script.Parent.MouseButton1Down:connect(function()
playing = not playing
script.Parent.Text = "Music: "..playing and "On" or "Off"
if playing then
playnext()
else
songs["song"..tostring(cursong)].Stop()
end
end)
Report Abuse
Hydroid18 is not online. Hydroid18
Joined: 15 Feb 2012
Total Posts: 144
04 Apr 2016 08:18 PM
@falsidge

Thank you for taking the time out of your day to help me.

I put this into my script, replacing the previous one and when I click the music button it does not turn on. I will try to change your version of the script.

(You seem to be more advanced than me in scripting XD)
Report Abuse
falsidge is not online. falsidge
Joined: 16 Jul 2013
Total Posts: 456
04 Apr 2016 08:22 PM
replace playing=true with playing=false
i realized that right after i posted
Report Abuse
SethTheMysterious is not online. SethTheMysterious
Joined: 21 Sep 2013
Total Posts: 88
04 Apr 2016 08:26 PM
Here, this script works in my game.

ID = 'MUSIC ID GOES HERE'
Looped = true

Music=Instance.new("Sound" ,workspace)
Music.Name = "Music"
if Looped == true then
Music.Looped = true
end
Music.SoundId = "THE WHOLE LINK TO THE AUDIO"
Music:Play(MUSIC ID GOES HERE AS WELL)


Add a "," after each id/link and put in the new one next to it. The just repeat.
Report Abuse
falsidge is not online. falsidge
Joined: 16 Jul 2013
Total Posts: 456
04 Apr 2016 08:35 PM
also all the periods before the Play() and stop() are supposed to be colon
and parenthesis around the condition in the text change


cursong=0
maxsongs=4
songs = script.Parent.Parent
playing=false
function playnext()
cursong=cursong+1
if cursong>maxsongs then
cursong=1
end
songs["song"..tostring(cursong)]:Play()
songs["song"..tostring(cursong)].Ended:connect(function()
if playing then
playnext()
end
end)
end

script.Parent.MouseButton1Down:connect(function()
playing = not playing
script.Parent.Text = "Music: "..(playing and "On" or "Off" )
if playing then
playnext()
else
songs["song"..tostring(cursong)]:Stop()
end
end)
Report Abuse
Hydroid18 is not online. Hydroid18
Joined: 15 Feb 2012
Total Posts: 144
04 Apr 2016 08:51 PM
It works now! Thank you so much! You are awesome! :D
Report Abuse
Hydroid18 is not online. Hydroid18
Joined: 15 Feb 2012
Total Posts: 144
04 Apr 2016 08:57 PM
Okay it crashed my roblox studio XD
Report Abuse
Hydroid18 is not online. Hydroid18
Joined: 15 Feb 2012
Total Posts: 144
04 Apr 2016 09:17 PM
Okay it has been resolved thanks to falsidge. Thank you falsidge!
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image