Guest User

Untitled

a guest
Dec 3rd, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. local localPlayerCharacter = game.Players.LocalPlayer.Character
  2. local playerHumanoid = game.Players.LocalPlayer.Character.Humanoid
  3. local currentSound = {} -- test, to hold current sound instance
  4.  
  5. --deletes all default roblox sounds
  6. for _, children in pairs (localPlayerCharacter.HumanoidRootPart:GetChildren("")) do
  7.  
  8. if children:IsA("Sound") then
  9.  
  10. children:Destroy()
  11.  
  12. end
  13. end
  14.  
  15. -- SoundId, pitch?, number Volume, boolean Looped (values are replaced in for loop below)
  16. local sounds = {
  17.  
  18. --[Enum.Material.Plastic] = nil,
  19. [Enum.Material.LeafyGrass] = {"http://www.roblox.com/asset/?id=16720281", 1, 1, true},
  20. [Enum.Material.Wood] = {"http://www.roblox.com/asset/?id=379484117", 1, .5, true}
  21.  
  22. }
  23.  
  24. --creates all the sounds, and then puts the sound instance in the array
  25. for material, data in pairs(sounds) do --material is the key, and data is the value inside the key
  26. local newSound = Instance.new("Sound", localPlayerCharacter.HumanoidRootPart)
  27. wait(1)
  28. newSound.Name = material.Name
  29. newSound.SoundId = data[1]
  30. newSound.Pitch = data[2]
  31. newSound.Volume = data[3]
  32. newSound.Looped = data[4]
  33. sounds[material] = {newSound} --places the new sound instance in the array, ready for use.
  34. end
  35.  
  36.  
  37. --is the player moving
  38. local isWalking
  39.  
  40. playerHumanoid.Running:connect(function(speed)
  41. if speed == 0 then
  42. --print("Player is not walking")
  43. isWalking = false
  44. else
  45. --print("Player is walking")
  46. isWalking = true
  47. end
  48. end)
  49.  
  50.  
  51.  
  52. --check if the player is touching the ground, not using right now
  53. function isGroundedFunc()
  54. if playerHumanoid.FloorMaterial ~= Enum.Material.Air then
  55. --print("Player is on the ground")
  56. return true
  57. else
  58. --print("Player is NOT on the ground!")
  59. end
  60. --print("Player is stepping on: ", playerHumanoid.FloorMaterial, type(playerHumanoid.FloorMaterial))
  61. end
  62. local isGrounded = isGroundedFunc()
  63.  
  64.  
  65. wait(5)--for debugging
  66. while wait() do
  67. local touchingMaterial = playerHumanoid.FloorMaterial
  68. if isWalking then
  69. if currentSound ~= touchingMaterial then
  70. if sounds[touchingMaterial] == nil then
  71. print("sounds[touchingMaterial == nil")
  72. else
  73. currentSound = sounds[touchingMaterial][1] --need to study what this does... kind of smart(including the stuff below)
  74. currentSound:Play()
  75. end
  76. end
  77. elseif isWalking == false then
  78.  
  79. sounds[touchingMaterial][1]:Stop()
  80. --currentSound:Stop()
  81. --currentSound = nil
  82. print("Did the sound stop?") -- Yes, it did. But only one instace of the sound did.
  83.  
  84. end
  85. end
Advertisement
Add Comment
Please, Sign In to add comment