Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local localPlayerCharacter = game.Players.LocalPlayer.Character
- local playerHumanoid = game.Players.LocalPlayer.Character.Humanoid
- local currentSound = {} -- test, to hold current sound instance
- --deletes all default roblox sounds
- for _, children in pairs (localPlayerCharacter.HumanoidRootPart:GetChildren("")) do
- if children:IsA("Sound") then
- children:Destroy()
- end
- end
- -- SoundId, pitch?, number Volume, boolean Looped (values are replaced in for loop below)
- local sounds = {
- --[Enum.Material.Plastic] = nil,
- [Enum.Material.LeafyGrass] = {"http://www.roblox.com/asset/?id=16720281", 1, 1, true},
- [Enum.Material.Wood] = {"http://www.roblox.com/asset/?id=379484117", 1, .5, true}
- }
- --creates all the sounds, and then puts the sound instance in the array
- for material, data in pairs(sounds) do --material is the key, and data is the value inside the key
- local newSound = Instance.new("Sound", localPlayerCharacter.HumanoidRootPart)
- wait(1)
- newSound.Name = material.Name
- newSound.SoundId = data[1]
- newSound.Pitch = data[2]
- newSound.Volume = data[3]
- newSound.Looped = data[4]
- sounds[material] = {newSound} --places the new sound instance in the array, ready for use.
- end
- --is the player moving
- local isWalking
- playerHumanoid.Running:connect(function(speed)
- if speed == 0 then
- --print("Player is not walking")
- isWalking = false
- else
- --print("Player is walking")
- isWalking = true
- end
- end)
- --check if the player is touching the ground, not using right now
- function isGroundedFunc()
- if playerHumanoid.FloorMaterial ~= Enum.Material.Air then
- --print("Player is on the ground")
- return true
- else
- --print("Player is NOT on the ground!")
- end
- --print("Player is stepping on: ", playerHumanoid.FloorMaterial, type(playerHumanoid.FloorMaterial))
- end
- local isGrounded = isGroundedFunc()
- wait(5)--for debugging
- while wait() do
- local touchingMaterial = playerHumanoid.FloorMaterial
- if isWalking then
- if currentSound ~= touchingMaterial then
- if sounds[touchingMaterial] == nil then
- print("sounds[touchingMaterial == nil")
- else
- currentSound = sounds[touchingMaterial][1] --need to study what this does... kind of smart(including the stuff below)
- currentSound:Play()
- end
- end
- elseif isWalking == false then
- sounds[touchingMaterial][1]:Stop()
- --currentSound:Stop()
- --currentSound = nil
- print("Did the sound stop?") -- Yes, it did. But only one instace of the sound did.
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment