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

My music script will not work what so ever?

Asked by 4 years ago

I have recently started ROBLOX Scripting, I am making a music script for my game, simple idea: It will play a sound twice then change the sound id I've tried two scripts:

script.Parent["SONG"].Looped = true -- Keep Songs Repeating
on = true -- do not change
-- DO NOT EDIT --

if on == true then
script.Parent["SONG"].SoundID = script.Parent["SOUND-1"].Value
script.Parent["SONG"]:play()
wait(script.Parent["Song"].TimeLength* 2)
script.Parent["SONG"]:Pause()
script.Parent["SONG"].SoundID = script.Parent["SOUND-2"].Value
script.Parent["SONG"]:Play()
wait(script.Parent["Song"].TimeLength* 2)
script.Parent["SONG"]:Pause()
script.Parent["SONG"].SoundID = script.Parent["SOUND-3"].Value
script.Parent["SONG"]:Play()
wait(script.Parent["Song"].TimeLength* 2)
script.Parent["SONG"]:Pause()
script.Parent["SONG"].SoundID = script.Parent["SOUND-3"].Value
script.Parent["SONG"]:Play()
wait(script.Parent["Song"].TimeLength* 2)
script.Parent["SONG"]:Pause()
script.Parent["SONG"].SoundID = script.Parent["SOUND-4"].Value
script.Parent["SONG"]:Play()
wait(script.Parent["Song"].TimeLength* 2)
script.Parent["SONG"]:Pause()
script.Parent["SONG"].SoundID = script.Parent["SOUND-5"].Value
script.Parent["SONG"]:Play()
end

and

local IDs = {
1236307446,
347962424,
344201558,
155305277,
1456224592
}
local Sound = Instance.new("Sound", script.Parent)
Sound.IsLooped = false
Sound.Volume = 1
while wait() do
  for i, v in pairs(IDs) do
    Sound.SoundId = "rbxassetid://"..v
    Sound.Playing = true
    wait(Sound.TimeLength * 2)
  end
end

neither scripts have returned any errors, what could I be doing wrong?

2 answers

Log in to vote
0
Answered by 4 years ago

Ah, you made an error with your 2nd script. "IsLooped" is not a property of audio. Try "looped" instead! :)

Here:

local IDs = {
1236307446,
347962424,
344201558,
155305277,
1456224592
}
local queue = 0
local Sound = Instance.new("Sound", script.Parent)
Sound.Volume = 1
Sound.Looped = false

function new_song()
    queue = queue + 1
    if IDs[queue] == nil then
        queue = 1
    end
    Sound.SoundId = "rbxassetid://" .. IDs[queue]
    Sound:Play()
end
new_song()
Sound.Stopped:Connect(new_song)

I also recommend sticking with events and not using infinite loops to check wether or not something has changed or not.

0
Works like a charm! Thank you! develop_dreams 0 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

I have already made a very innefficient music script which may or may not loop.

    print ("song1")
    music.SoundId = "http://www.roblox.com/asset/?id=IDHERE"

    music:play()
    music.Ended:Wait()
    music:stop()

    print ("song2")
    music.SoundId = "http://www.roblox.com/asset/?id=IDHERE"

    music:play()
    music.Ended:Wait()
    music:stop()

It's pretty glitchy, but you can use some of this script if you want.

Answer this question