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

1 comment
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?