Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --StarterPlayer >> StarterCharacterScripts >> Create a Script >> Write this >>
- local players = game:GetService("Players")
- local replicatedStorage = game:GetService("ReplicatedStorage")
- -- Set local variables
- local player = players:GetPlayerFromCharacter(script.Parent)
- local character = player.Character or player.CharacterAdded:wait()
- local humanoid = character.Humanoid
- -- Create sound variables
- local id
- local volume
- local playbackSpeed
- -- Create material variables
- local floorMaterial
- local material
- -- Create remote instance
- local updateWalkspeedRemote = Instance.new("RemoteEvent", game.ReplicatedStorage)
- updateWalkspeedRemote.Name = "UpdateWalkspeed"
- -- Create sound instance
- local currentSound = Instance.new("Sound", character.HumanoidRootPart)
- currentSound.Name = "CurrentSound"
- currentSound.RollOffMode = Enum.RollOffMode.Linear -- you can experiment with this value
- currentSound.RollOffMinDistance = 10 -- When should the sound start fading out? (in studs)
- currentSound.RollOffMaxDistance = 75 -- When should the sound stop being heard? (in studs)
- -- Fetch the ID list
- local IDList = require(script:FindFirstChildWhichIsA("ModuleScript"))
- -- Get the current floor material.
- local function getFloorMaterial()
- floorMaterial = humanoid.FloorMaterial
- material = string.split(tostring(floorMaterial), "Enum.Material.")[2]
- return material
- end
- -- Get the correct sound from our sound list.
- local function getSoundProperties()
- for name, data in pairs(IDList) do
- if name == material then
- id = data.id
- volume = data.volume
- playbackSpeed = (humanoid.WalkSpeed / 16) * data.speed
- break
- end
- end
- end
- -- update the sound data
- local function update()
- currentSound.SoundId = id
- currentSound.Volume = volume
- currentSound.PlaybackSpeed = playbackSpeed
- end
- -- Update the previous floor material, current floor material and sound data
- -- !! BUGGED AS OF THE LATEST ROBLOX UPDATE !!
- --humanoid:GetPropertyChangedSignal("FloorMaterial"):Connect(function()
- -- getFloorMaterial()
- -- getSoundProperties()
- -- update()
- -- if humanoid.MoveDirection.Magnitude > 0 then
- -- currentSound.Playing = true
- -- end
- --end)
- -- !! BUGGED AS OF THE LATEST ROBLOX UPDATE !!
- updateWalkspeedRemote.OnServerEvent:Connect(function(player, walkspeed)
- player.Character.Humanoid.WalkSpeed = walkspeed
- end)
- -- check if the player is moving and not climbing
- humanoid.Running:Connect(function(speed)
- if humanoid.MoveDirection.Magnitude > 0 and speed > 0 and humanoid:GetState() ~= Enum.HumanoidStateType.Climbing then
- getSoundProperties()
- update()
- currentSound.Playing = true
- currentSound.Looped = true
- else
- currentSound:Stop()
- end
- end)
- -- Scuffed solution to 'humanoid:GetPropertyChangedSignal('FloorMaterial')' not working as expected on the server.
- spawn(function()
- while task.wait() do
- if humanoid.FloorMaterial ~= floorMaterial then
- getFloorMaterial()
- getSoundProperties()
- update()
- end
- end
- end)
- print("Walking sounds successfully loaded!")
- --Your script >> press "+" >> Add a LocalScript >> Write This >>
- local players = game:GetService("Players")
- local soundService = game:GetService("SoundService")
- local replicatedStorage = game:GetService("ReplicatedStorage")
- -- Set local variables
- local player = players.LocalPlayer
- local character = player.Character or player.CharacterAdded:wait()
- local humanoid = character.Humanoid
- -- Create sound variables
- local id
- local volume
- local playbackSpeed
- -- Create material variables
- local floorMaterial
- local material
- -- Get the HumanoidRootPart and wait for the server audio
- local root = character:WaitForChild("HumanoidRootPart")
- local serverSound = root:WaitForChild("CurrentSound")
- -- Get remote
- local updateWalkspeedRemote = replicatedStorage:WaitForChild("UpdateWalkspeed")
- -- Create sound instance
- local currentSound = Instance.new("Sound", soundService)
- currentSound.Name = "CurrentSound"
- -- fetch the ID list
- local IDList = require(script.Parent:FindFirstChildWhichIsA("ModuleScript"))
- -- Delete default running sound
- character.HumanoidRootPart:FindFirstChild("Running"):Destroy()
- -- Get the current floor material.
- local function getFloorMaterial()
- floorMaterial = humanoid.FloorMaterial
- material = string.split(tostring(floorMaterial), "Enum.Material.")[2]
- return material
- end
- -- Get the correct sound from our sound list.
- local function getSoundProperties()
- for name, data in pairs(IDList) do
- if name == material then
- id = data.id
- volume = data.volume
- playbackSpeed = (humanoid.WalkSpeed / 16) * data.speed
- break
- end
- end
- end
- -- update the sound data
- local function update()
- currentSound.SoundId = id
- currentSound.Volume = volume
- currentSound.PlaybackSpeed = playbackSpeed
- end
- -- Get initial data for client
- getFloorMaterial()
- getSoundProperties()
- update()
- -- Update the previous floor material and current floor material
- humanoid:GetPropertyChangedSignal("FloorMaterial"):Connect(function()
- getFloorMaterial()
- getSoundProperties()
- update()
- if humanoid.MoveDirection.Magnitude > 0 then
- currentSound.Playing = true
- end
- end)
- -- Let the server know our walkspeed has changed
- humanoid:GetPropertyChangedSignal("WalkSpeed"):Connect(function()
- updateWalkspeedRemote:FireServer(humanoid.WalkSpeed)
- end)
- -- check if the player is moving and not climbing
- humanoid.Running:Connect(function(speed)
- if humanoid.MoveDirection.Magnitude > 0 and speed > 0 and humanoid:GetState() ~= Enum.HumanoidStateType.Climbing then
- getSoundProperties()
- update()
- currentSound.Playing = true
- currentSound.Looped = true
- else
- currentSound:Stop()
- end
- end)
- serverSound.Changed:Connect(function(Volume)
- if Volume ~= 0 then
- serverSound.Volume = 0
- end
- end)
- -- Small bug fix where the sound would start playing after the player joined
- player.CharacterAdded:Connect(function()
- task.wait(1)
- if currentSound.IsPlaying then
- currentSound:Stop()
- end
- end)
- print("Walking sounds successfully loaded!")
- --In the first Script created >> press "+" >> Add a ModuleScript >> Write This >>
- local IDList = {
- Air = {id = "rbxassetid://329997777", volume = 0, speed = 1.00},
- Asphalt = {id = "rbxassetid://277067660", volume = 0.60, speed = 1.00},
- Basalt = {id = "rbxassetid://3190903775", volume = 0.60, speed = 1.00},
- Brick = {id = "rbxassetid://178190837", volume = 0.60, speed = 1.00},
- Cobblestone = {id = "rbxassetid://178190837", volume = 0.60, speed = 1.00},
- Concrete = {id = "rbxassetid://277067660", volume = 0.60, speed = 1.00},
- CorrodedMetal = {id = "rbxassetid://177940974", volume = 0.60, speed = 1.00},
- CrackedLava = {id = "rbxassetid://3190903775", volume = 0.60, speed = 1.00},
- DiamondPlate = {id = "rbxassetid://177940974", volume = 0.60, speed = 1.00},
- Fabric = {id = "rbxassetid://9083849830", volume = 0.40, speed = 1.00},
- Foil = {id = "rbxassetid://178190837", volume = 0.60, speed = 1.00},
- Forcefield = {id = "rbxassetid://329997777", volume = 0.60, speed = 1.00},
- Glass = {id = "rbxassetid://178190837", volume = 0.60, speed = 1.00},
- Granite = {id = "rbxassetid://178054124", volume = 0.60, speed = 1.00},
- Grass = {id = "rbxassetid://9064714296", volume = 0.60, speed = 1.00},
- Glacier = {id = "rbxassetid://7047108275", volume = 0.40, speed = 1.00},
- Ground = {id = "rbxassetid://9064714296", volume = 0.60, speed = 1.00},
- Ice = {id = "rbxassetid://7047108275", volume = 0.40, speed = 1.00},
- Limestone = {id = "rbxassetid://9083846829", volume = 0.60, speed = 1.00},
- LeafyGrass = {id = "rbxassetid://3098847639", volume = 0.60, speed = 1.00},
- Marble = {id = "rbxassetid://178190837", volume = 0.60, speed = 1.00},
- Metal = {id = "rbxassetid://177940974", volume = 0.60, speed = 1.00},
- Mud = {id = "rbxassetid://6441160246", volume = 0.60, speed = 1.00},
- Neon = {id = "rbxassetid://177940974", volume = 0.60, speed = 1.00},
- Pebble = {id = "rbxassetid://178190837", volume = 0.60, speed = 1.00},
- Plastic = {id = "rbxassetid://4416041299", volume = 0.60, speed = 1.40},
- Pavement = {id = "rbxassetid://277067660", volume = 0.60, speed = 1.00},
- Rock = {id = "rbxassetid://178190837", volume = 0.60, speed = 1.00},
- Sand = {id = "rbxassetid://9083846829", volume = 0.40, speed = 1.00},
- Slate = {id = "rbxassetid://178054124", volume = 0.60, speed = 1.00},
- Snow = {id = "rbxassetid://8453425942", volume = 0.60, speed = 1.00},
- Salt = {id = "rbxassetid://9083846829", volume = 0.40, speed = 1.00},
- Sandstone = {id = "rbxassetid://3190903775", volume = 0.60, speed = 0.75},
- SmoothPlastic = {id = "rbxassetid://178190837", volume = 0.60, speed = 1.00},
- Wood = {id = "rbxassetid://3199270096", volume = 0.60, speed = 1.00},
- WoodPlanks = {id = "rbxassetid://211987063", volume = 0.60, speed = 1.00}
- }
- return IDList
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement