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

Can you fix my Music Script?

Asked by 9 years ago

I made a music script for my game but it isn't working. I am actually kind of a beginner in scripting, so I am not sure whether I messed it up or not. This is the script:

local sound = game.Workspace.Model.Script["Jingle Bells"]
local sound = game.Workspace.Model.Script["O Christmas Tree: Part 1"]
local sound = game.Workspace.Model.Script["O Christmas Tree: Part 2"]
local sound = game.Workspace.Model.Script["We Wish You A Merry Christmas"]

--Put Sound Id Here V
local sound = game.Workspace.Model.Script["Jingle Bells"]
Sound = 138080071
O = Instance.new("Sound",workspace)
O.SoundId = ("http://www.roblox.com/asset/?id=138080071"..Sound)
O.Pitch = 1
O.Volume = 1
O.Looped = true 
O:Play()
wait(10)
O:Stop()

local sound = game.Workspace.Model.Script["O Christmas Tree: Part 1"]
Sound = 142558373
O = Instance.new("Sound",workspace)
O.SoundId = ("http://www.roblox.com/asset/?id=142558373"..Sound)
O.Pitch = 1
O.Volume = 1
O.Looped = true 
O:Play()
wait(120)
O:Stop()

local sound = game.Workspace.Model.Script["O Christmas Tree: Part 2"]
Sound = 142558605
O = Instance.new("Sound",workspace)
O.SoundId = ("http://www.roblox.com/asset/?id=142558605"..Sound)
O.Pitch = 1
O.Volume = 1
O.Looped = true 
O:Play()
wait(120)
O:Stop()

local sound = game.Workspace.Model.Script["We Wish You A Merry Christmas"]
Sound = 137355348
O = Instance.new("Sound",workspace)
O.SoundId = ("http://www.roblox.com/asset/?id=137355348"..Sound)
O.Pitch = 1
O.Volume = 1
O.Looped = true 
O:Play()
wait(45)
O:Stop()

while true do
    --Play Jingle Bells
    Sound = 138080071

    --Play O Christmas Tree: Part 1
    Sound = 142558373

    --Play O Christmas Tree: Part 2
    Sound = 142558605

    --Play We Wish You A Merry Christmas
    Sound = 137355348
end

0
Are "Jingle Bells", "O Christmas Tree: Part 1", etc all Sounds? DaMrNelson 130 — 9y
0
O.SoundId = ("http://www.roblox.com/asset/?id=137355348"..Sound) you're putting the ID twice. Try removing `..Sound`? Vrakos 109 — 9y

1 answer

Log in to vote
2
Answered by 9 years ago

What you're doing is quite inefficient. First of all, on lines 1-4 you keep redefining what the value of 'sound' is, this will leave the value at the end as the last one you defined it as. You are only defining the value of 'sound' you never actually use it in any part of the script. You then put 2 of the IDs at the end of the asset link. The loop at the end would cause the game to crash as you have no pauses and it would actually do nothing but change the value and do nothing with it. All you need is a script like this in workspace:

Sound = Instance.new("Sound",game.Workspace) -- Creates a sound and sets it's parent as workspace.
JingleBells = 138080071
OChristmasTree1 = 142558373
OChristmasTree2 = 142558605
WeWishYouAMerryChristmas = 137355348

while true do -- Create an infinite loop
    Sound.SoundId = "http://www.roblox.com/asset/?id="..JingleBells  -- Set the ID to Jingle Bells
    Sound:Play() -- Play the sound, there's no need to set the pitch or volume, they're both 1 by default
    wait(10) -- Wait for the song to stop
    Sound:Stop()
    Sound.SoundId = "http://www.roblox.com/asset/?id="..OChristmasTree1 -- Set the ID to O Christmas Tree Part 1
    Sound:Play() -- Play the sound, there's no need to set the pitch or volume, they're both 1 by default
    wait(120) -- Wait for the song to stop
    Sound:Stop()
    Sound.SoundId = "http://www.roblox.com/asset/?id="..OChristmasTree2 -- Set the ID to O Christmas Tree Part 2
    Sound:Play() -- Play the sound, there's no need to set the pitch or volume, they're both 1 by default
    wait(120) -- Wait for the song to stop
    Sound:Stop()
    Sound.SoundId = "http://www.roblox.com/asset/?id="..WeWishYouAMerryChristmas -- Set the ID to We Wish You A Merry Christmas
    Sound:Play() -- Play the sound, there's no need to set the pitch or volume, they're both 1 by default
    wait(45) -- Wait for the song to stop
    Sound:Stop()
end
0
Thank you bro. User#5689 -1 — 9y
Ad

Answer this question