local mesh = script.Parent.Mesh local music = script.Parent.Music local playingmusic = false function choosemusic() music.Volume = 0.1 music.TimePosition = 0 local song = math.random(1, 12) if song == 1 then music.SoundId = "rbxassetid://406637473" end if song == 2 then music.SoundId = "rbxassetid://406637473" music.TimePosition = 1 end if song == 3 then music.SoundId = "rbxassetid://406637473" end if song == 4 then music.SoundId = "rbxassetid://406637473" end if song == 5 then music.SoundId = "rbxassetid://672731096" end if song == 6 then music.SoundId = "rbxassetid://386781032" end if song == 7 then music.SoundId = "rbxassetid://386781032" music.TimePosition = 1.5 end if song == 8 then music.SoundId = "rbxassetid://386781032" end if song == 9 then music.SoundId = "rbxassetid://386781032" end if song == 10 then music.SoundId = "rbxassetid://791467527" music.Volume = 0.3 end if song == 11 then music.SoundId = "rbxassetid://791467527" end if song == 12 then music.SoundId = "rbxassetid://791467527" end music:Play() end while true do music:Stop() wait(5) choosemusic() playingmusic = true coroutine.resume(coroutine.create(function() repeat wait() mesh.Scale = mesh.Scale + Vector3.new(0.025, 0.025, 0.025) wait() mesh.Scale = mesh.Scale + Vector3.new(0.025, 0.025, 0.025) wait() mesh.Scale = mesh.Scale + Vector3.new(0.025, 0.025, 0.025) wait() mesh.Scale = mesh.Scale - Vector3.new(0.025, 0.025, 0.025) wait() mesh.Scale = mesh.Scale - Vector3.new(0.025, 0.025, 0.025) wait() mesh.Scale = mesh.Scale - Vector3.new(0.025, 0.025, 0.025) until playingmusic == false end)) wait(130) playingmusic = false local isOn = true local music = script.Parent.Music function on() music:Play() end script.Parent.click.ClickDetector.MouseClick:connect(OnClicked()) function off() music:Stop() end function OnClicked() if isOn == true then isOn = false off() isOn = false off() else if isOn == false then isOn = true on() on() end end end script.Parent.click.ClickDetector.MouseClick:connect(OnClicked) on() end
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)
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.
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:
function OnClicked() if IsOn then isOn = false off() else isOn = true on() end end
Hope this helped! Leave a comment if you need further assistance