Can anyone help me out here as to why the script is not functioning.
Here is the script that supposed to change walk sounds across different materials.
local char = script.Parent
delay(0, function()
while wait() do if char.Humanoid.FloorMaterial == Enum.Material.Grass or char.Humanoid.FloorMaterial == Enum.Material.Sand then char.Head.Running.SoundId = "rbxassetid://510933218" char.Head.Running.Volume = 1 elseif char.Humanoid.FloorMaterial == Enum.Material.Wood or char.Humanoid.FloorMaterial == Enum.Material.Rock then char.Head.Running.SoundId = "rbxassetid://2991635108" char.Head.Running.Volume = .1 end end
end)
-- Client Script -- Place into StarterCharacterScripts as Local Script local Players = game:GetService("Players") -- Player Service local LocalPlayer = Players.LocalPlayer -- Local Player local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait() -- Local Player's character repeat wait() until Character and game:IsLoaded() -- Once everything is loaded properly. local Humanoid = Character.Humanoid -- Our humanoid to retrieve our FloorMaterial property local HumanoidRootPart = Character.HumanoidRootPart -- Character HRP local RunningSound = HumanoidRootPart.Running -- Our running sound. local OldSoundID, OldSoundVol -- We'll need these if the material type doesn't match OldSoundID = RunningSound.SoundId OldSoundVol = RunningSound.Volume local MaterialTypes = { -- Our material types. ['Glass'] = Enum.Material.Glass; ['Sand'] = Enum.Material.Sand; ['Wood'] = Enum.Material.Wood; ['Rock'] = Enum.Material.Rock; } local CheckIfMaterial = function(Material) if Humanoid.FloorMaterial == Material then return true end return false end --[[ CheckIfMateiral Function Argument[1] - Material Input Returns true/false depending if the FloorMaterial is valid to the arguement given. ]] Humanoid:GetPropertyChangedSignal('FloorMaterial'):Connect(function() -- Our event to check if FloorMaterial gets changed if CheckIfMaterial(MaterialTypes.Glass) or CheckIfMaterial(MaterialTypes.Sand) then -- Checking if Glass or Sand for FloorMaterial RunningSound.SoundId = "rbxassetid://510933218" -- Sets to ID RunningSound.Volume = 1 -- Volume set elseif CheckIfMaterial(MaterialTypes.Wood) or CheckIfMaterial(MaterialTypes.Rock) then -- Same as above RunningSound.SoundId = "rbxassetid://2991635108" RunningSound.Volume = .1 else -- If not's matching anything of the above we set to normal walking sound. Optional, you can remove this but i thought you needed it anyways. RunningSound.SoundId = OldSoundID RunningSound.Volume = OldSoundVol end end)
I've tested this and works perfectly according to what you needed to be fixed and what you wanted. Keep notes of this code and remember that there's events for the Humanoid which can make your process 10x easier and far more efficient. See you around, have a nice day.
Although i'm sorry this could've been much more simplified but i was bored and tired at the time, might update it later.