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

Music Duplicates itself??

Asked by 9 years ago

I created a Music thing for my holo in case trainers wanted to have music in their trainings. I know most of them want music. So I decided to add music into the holo depending on the map loaded. When you load the first map (load.sft) it works perfectly fine...until you load the second one. When you do, the sound duplicates itself, yet there is only one Sound object!! Is this ROBLOX's problem? Or did I screw it up somehow?

Here is the code inside the sound:

game.Workspace.Music.Changed:connect(function(v)
    if v == true then
        script.Parent:Play()
    elseif v == false then
        script.Parent:Stop()
    end
end)

script.Parent.Changed:connect(function(v)
    if v == "SoundId" and v.SoundId == "http://roblox.com/asset/?id=193160512" then --You got a problem with Portal 2 music?
        script.Parent.Pitch = math.random(15, 20)/10
    elseif v == "SoundId" and v.SoundId == "http://roblox.com/asset/?id=146320539" then
        script.Parent.Pitch = math.random(75, 125)/100
    elseif v == "SoundId" and v.SoundId == "http://roblox.com/asset/?id=149228598" then
        script.Parent.Pitch = math.random(15, 20)/10
    else
        script.Parent.Pitch = 1
    end
end)

The Module script in workspace. It runs inside ServerScripts in a map that is in a model:

local module = {}

module.Ready = function(track)
    workspace.MusicSound:Stop()
    workspace.MusicSound.SoundId = track.SoundId
    wait(1)
    if workspace.Music.Value then
        workspace.MusicSound:Play()
    end
end

return module
0
I need more information, first off, check to make sure there is only one sound object in workspace, also, what type of script are you using, a normal one? I know the bottom is a module script. And why a module script? dragonkeeper467 453 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago
game.Workspace.Music.Changed:connect(function(v)
    if v == true then
        script.Parent:Play()
    wait (1) -- 1 should be replaced with the duration of the music, or it will repeat. The duration can be found in the audio's explorer thingy if you play it.
    elseif v == false then
        script.Parent:Stop()
    end
end)

0
That isn't what I meant...I want it to loop, yes, but I don't want it to duplicate and play two music at the same time lightpower26 399 — 9y
Ad

Answer this question