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 » Scripting Helpers
Home Search
 

Re: Need help making a toggle on/off

Previous Thread :: Next Thread 
SteamRail is not online. SteamRail
Joined: 26 Jul 2008
Total Posts: 1147
14 Aug 2014 11:52 PM
So I got the script to work by clicking the left mouse button on the TextButton so it would play the music. Well that's great and all but now I need a way to turn it off with same button. I got it to work with the right mouse button but I want to be able to toggle on/off with the same button, how could I do this?

This is what I got:

function Music()
script.Parent.BackGround:play()
end

script.Parent.MouseButton1Click:connect(Music)

function MusicOff()
script.Parent.BackGround:stop()
end

script.Parent.MouseButton2Click:connect(MusicOff)

Report Abuse
SteamRail is not online. SteamRail
Joined: 26 Jul 2008
Total Posts: 1147
19 Aug 2014 07:55 PM
b1
Report Abuse
blockoo is not online. blockoo
Joined: 08 Nov 2007
Total Posts: 17202
19 Aug 2014 08:02 PM
on = false

function turnOn()
if (on == false) then
on = true
--do stuff for turning it on
end
end

function turnOff()
if (on == true) then
on = false
--do stuff for turning it off
end
end

Button.MouseButton1Click:connect(turnOn)
Button.MouseButton1Click:connect(turnOff)
Report Abuse
4567777 is not online. 4567777
Joined: 13 Jul 2013
Total Posts: 128
19 Aug 2014 08:03 PM
on=false
function music()
on = not on
if(on)then
script.Parent.BackGround:play()
else
script.Parent.BackGround:stop()
end
end

script.Parent.MouseButton1Click:connect(music)
Report Abuse
blockoo is not online. blockoo
Joined: 08 Nov 2007
Total Posts: 17202
19 Aug 2014 08:05 PM
Oh wow, I derped. Don't know why I used 2 functions...
Report Abuse
SteamRail is not online. SteamRail
Joined: 26 Jul 2008
Total Posts: 1147
19 Aug 2014 08:28 PM
Thank you
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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