Advertisement
Hmm465_Gaming

Force Audio Player

May 6th, 2018
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.11 KB | None | 0 0
  1. local MusicID = 0 --replace number with a sound id
  2. local MusicPitch = 1
  3. local MusicVolume = 1
  4.  
  5. print("forcing audio")
  6.  
  7. local IN = Instance.new
  8.  
  9. local Frame_Speed = 60
  10.  
  11. local ArtificialHB = IN("BindableEvent", script)
  12. ArtificialHB.Name = "Heartbeat"
  13.  
  14. script:WaitForChild("Heartbeat")
  15.  
  16. local tf = 0
  17. local allowframeloss = false
  18. local tossremainder = false
  19. local lastframe = tick()
  20. local frame = 1/Frame_Speed
  21. ArtificialHB:Fire()
  22.  
  23. game:GetService("RunService").Heartbeat:connect(function(s, p)
  24.     tf = tf + s
  25.     if tf >= frame then
  26.         if allowframeloss then
  27.             script.Heartbeat:Fire()
  28.             lastframe = tick()
  29.         else
  30.             for i = 1, math.floor(tf / frame) do
  31.                 ArtificialHB:Fire()
  32.             end
  33.             lastframe = tick()
  34.         end
  35.         if tossremainder then
  36.             tf = 0
  37.         else
  38.             tf = tf - frame * math.floor(tf / frame)
  39.         end
  40.     end
  41. end)
  42.  
  43. function swait(num)
  44.     if num == 0 or num == nil then
  45.         ArtificialHB.Event:wait()
  46.     else
  47.         for i = 0, num do
  48.             ArtificialHB.Event:wait()
  49.         end
  50.     end
  51. end
  52.  
  53. local S = setmetatable({},{__index = function(s,i) return game:service(i) end})
  54. local Plrs = S.Players
  55. local Plr = Plrs.LocalPlayer
  56. local Char = Plr.Character
  57.  
  58. function Sound(parent,id,pitch,volume,looped,effect,autoPlay)
  59.     local Sound = IN("Sound")
  60.     Sound.SoundId = "rbxassetid://".. tostring(id or 0)
  61.     Sound.Pitch = pitch or 1
  62.     Sound.Volume = volume or 1
  63.     Sound.Looped = looped or false
  64.     if(autoPlay)then
  65.         coroutine.wrap(function()
  66.             repeat wait() until Sound.IsLoaded
  67.             Sound.Playing = autoPlay or false
  68.         end)()
  69.     end
  70.     if(not looped and effect)then
  71.         Sound.Ended:connect(function()
  72.             Sound.Volume = 0
  73.             Sound:destroy()
  74.         end)
  75.     elseif(effect)then
  76.         warn("Sound can't be looped and a sound effect!")
  77.     end
  78.     Sound.Parent =parent or Torso
  79.     return Sound
  80. end
  81.  
  82. local Music = Sound(game.Workspace,MusicID,MusicPitch,MusicVolume,true,false,true)
  83. Music.Name = 'Music'
  84.  
  85.  
  86. while true do
  87.     swait()
  88.     if(not Music or not Music.Parent)then
  89.     print("deleted")
  90.         local a = Music.TimePosition
  91.         Music = Sound(game.Workspace,MusicID,MusicPitch,MusicVolume,true,false,true)
  92.         Music.Name = 'Music'
  93.         Music.TimePosition = a
  94.     end
  95. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement