Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How would I make it so if I clicked a radio it would turn of the music?

Asked by 4 years ago
Edited 4 years ago
001local mesh = script.Parent.Mesh
002local music = script.Parent.Music
003local playingmusic = false
004 
005function choosemusic()
006    music.Volume = 0.1
007    music.TimePosition = 0
008    local song = math.random(1, 12)
009    if song == 1 then
010        music.SoundId = "rbxassetid://406637473"
011    end
012    if song == 2 then
013        music.SoundId = "rbxassetid://406637473"
014        music.TimePosition = 1
015    end
View all 106 lines...

This is the whole code for the radio and at the bottom is where I want it to be able to turn off and on again (Sorry for wasting you're time i'm just new and have no clue what to do)

0
If anyone could tell me what's wrong with the script and help me that would be nice Asherharding10 12 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Did you get the off() and on() functions mixed up? the off() function is playing the music whilst the on() function is stopping the music.

0
Please read and interpret the code before giving an answer NinjaManChase 226 — 4y
0
It does seem like I mixed up the on and off function.. but when i switched it and then I clicked the radio it didn't turn off Asherharding10 12 — 4y
0
You need to use the isOn variable and set it to true/false depending on if the radio is turned of or not. something like "if isOn == true then isOn = false off()" and "if isOn == false then isOn = true on()" DaysWeeksAndMonths 90 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

Hello, my name is NinjaManChase and I'll try to answer your question as simply as possible :)

It appears that you never toggled isOn. This means that the script always thinks your radio is offline.

We can fix your code by replacing your onClicked function with:

01function OnClicked()
02 
03    if IsOn then
04        isOn = false
05        off()
06    else
07        isOn = true
08        on()
09    end
10end

Hope this helped! Leave a comment if you need further assistance

0
Hello, and thanks for assisting me, but it appears when I click it, it doesn't turn off.. if I wasn't clear. When you go into game the radio is playing. Asherharding10 12 — 4y
0
turn isOn to true or run off before the OnClicked function in your script NinjaManChase 226 — 4y

Answer this question