Mryeetmemes

Sound_Birds script in new roblox studio template

May 15th, 2023
564
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.99 KB | None | 0 0
  1. local SoundPlayer = require(script.SoundPlayer)
  2. local rng = Random.new()
  3.  
  4. while not script.Sounds.Value do wait() end
  5. while not script.Part.Value do wait() end
  6.  
  7. function PositionWithin(part: Part?) : Vector3?
  8.     if not part then return nil end
  9.    
  10.     local halfSize = part.Size / 2
  11.     local offset = Vector3.new(
  12.         rng:NextNumber(-halfSize.X, halfSize.X),
  13.         rng:NextNumber(-halfSize.Y, halfSize.Y),
  14.         rng:NextNumber(-halfSize.Z, halfSize.Z)
  15.     )
  16.     return part.CFrame:PointToWorldSpace(offset)
  17. end
  18.  
  19. while true do
  20.     local playbackInterval = script:GetAttribute("PlaybackInterval")
  21.     wait(rng:NextNumber(playbackInterval.Min, playbackInterval.Max))
  22.    
  23.     local isVolumetric = script:GetAttribute("IsVolumetric") or false
  24.     local Sounds = script.Sounds.Value
  25.     local Part = script.Part.Value
  26.    
  27.     local from = if isVolumetric then Part else PositionWithin(Part)
  28.    
  29.     if script:GetAttribute("VisualizeEmitters") then
  30.         SoundPlayer.PlayWithVisuals(Sounds, from)
  31.     else
  32.         SoundPlayer.Play(Sounds, from)
  33.     end
  34. end
  35.  
Advertisement
Add Comment
Please, Sign In to add comment