Advertisement
C1oseReaper

ROBLOX LUA SOUND LOCAL SCRIPT

Feb 19th, 2020
3,011
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. local SoundRegionWorkspace = game.Workspace:WaitForChild("SoundRegion")
  2.  
  3. local Found = false
  4.  
  5. while wait(1) do
  6.  
  7. for i, v in pairs(SoundRegionWorkspace:GetChildren()) do
  8.  
  9. Found = false
  10. local region = Region3.new(v.Position - (v.Size/2), v.Position + (v.Size/2))
  11.  
  12. local parts = game.Workspace:FindPartsInRegion3WithWhiteList(region, game.Players.LocalPlayer.Character:GetDescendants())
  13.  
  14. for _, part in pairs(parts) do
  15. -- Loop one by one through the parts table
  16. if part:FindFirstAncestor(game.Players.LocalPlayer.Name) then
  17. print("Player was found")
  18. Found = true
  19. break
  20. else
  21. Found = false
  22. print("Player was not found in region")
  23. end
  24.  
  25. end
  26.  
  27. if Found == true then
  28. -- Start playing some music
  29. if script.Parent.SoundRegion[v.Name].IsPlaying == false then
  30. script.Parent.SoundRegion[v.Name]:Play()
  31. break
  32. end
  33. else
  34. script.Parent.SoundRegion[v.Name]:Stop()
  35. end
  36.  
  37.  
  38. end
  39. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement