Advertisement
HowToRoblox

AreaMusicHandler

Jul 25th, 2020
4,142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.54 KB | None | 0 0
  1. local sound = Instance.new("Sound")
  2.  
  3. sound.Looped = true
  4.  
  5. sound.Parent = script
  6.  
  7.  
  8. local char = script.Parent
  9. local humanoid = char:WaitForChild("Humanoid")
  10.  
  11.  
  12. local areasGroup = workspace:WaitForChild("Areas")
  13.  
  14.  
  15. humanoid.Touched:Connect(function(touchedPart)
  16.    
  17.     if touchedPart.Parent == areasGroup then
  18.        
  19.         sound.SoundId = touchedPart.Music.SoundId
  20.        
  21.         sound:Play()
  22.        
  23.         touchedPart.TouchEnded:Connect(function(touchEndedPart)
  24.            
  25.             if touchEndedPart.Parent == char then
  26.                
  27.                 sound:Stop()
  28.             end
  29.         end)
  30.     end
  31. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement