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
|
  |
| 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
|
  |
| 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 |
|
|
|
| 04 Apr 2016 03:21 PM |
I just.. I can't. I'm sorry.
|
|
|
| Report Abuse |
|
|
Hydroid18
|
  |
| Joined: 15 Feb 2012 |
| Total Posts: 144 |
|
| |
|
Hydroid18
|
  |
| Joined: 15 Feb 2012 |
| Total Posts: 144 |
|
| |
|
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
|
  |
| 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
|
  |
| 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 |
|
|
|
| 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
|
  |
| 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
|
  |
| 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
|
  |
| Joined: 15 Feb 2012 |
| Total Posts: 144 |
|
|
| 04 Apr 2016 08:57 PM |
| Okay it crashed my roblox studio XD |
|
|
| Report Abuse |
|
|
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 |
|
|