mr2meows

g

Jul 7th, 2022 (edited)
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. -- util
  2. for i,v in pairs(owner.Character.HumanoidRootPart:GetChildren()) do
  3. if v:IsA("Sound") then
  4. v:Destroy()
  5. end
  6. end
  7.  
  8. function waitForChild(parent, childName)
  9. local child = parent:findFirstChild(childName)
  10. if child then return child end
  11. while true do
  12. child = parent.ChildAdded:wait()
  13. if child.Name==childName then return child end
  14. end
  15. end
  16.  
  17. function newSound(id)
  18. local sound = Instance.new("Sound")
  19. sound.SoundId = id
  20. sound.archivable = false
  21. sound.Parent = owner.Character.Head
  22. return sound
  23. end
  24.  
  25. -- declarations
  26.  
  27. local sDied = newSound("rbxasset://sounds/uuhhh.wav")
  28. local sFallingDown = newSound("rbxasset://sounds/splat.wav")
  29. local sFreeFalling = newSound("rbxasset://sounds/swoosh.wav")
  30. local sGettingUp = newSound("rbxasset://sounds/hit.wav")
  31. local sJumping = newSound("rbxasset://sounds/button.wav")
  32. local sRunning = newSound("rbxasset://sounds/bfsl-minifigfoots1.mp3")
  33. sRunning.Looped = true
  34.  
  35. local Figure = owner.Character
  36. local Head = waitForChild(Figure, "Head")
  37. local Humanoid = waitForChild(Figure, "Humanoid")
  38.  
  39. -- functions
  40.  
  41. function onDied()
  42. sDied:Play()
  43. end
  44.  
  45. function onState(state, sound)
  46. if state then
  47. sound:Play()
  48. else
  49. sound:Pause()
  50. end
  51. end
  52.  
  53. function onRunning(speed)
  54. if speed>0 then
  55. sRunning:Play()
  56. else
  57. sRunning:Pause()
  58. end
  59. end
  60.  
  61. -- connect up
  62.  
  63. Humanoid.Died:connect(onDied)
  64. Humanoid.Running:connect(onRunning)
  65. Humanoid.Jumping:connect(function(state) onState(state, sJumping) end)
  66. Humanoid.GettingUp:connect(function(state) onState(state, sGettingUp) end)
  67. Humanoid.FreeFalling:connect(function(state) onState(state, sFreeFalling) end)
  68. Humanoid.FallingDown:connect(function(state) onState(state, sFallingDown) end)
  69.  
Add Comment
Please, Sign In to add comment