One of my games has a footstep script that uses Animation Events and has multiple sounds to each material there currently is. But, for some reason, it only plays the default footsteps (which is Plastic) and not the other ones (ex. Concrete, Pebble, Snow, Metal, etc)
Here’s the entire script that handles the footsteps
local player = game.Players.LocalPlayer
local Char = player.Character or player.CharacterAdded:Wait()
local HRP = script.Parent:WaitForChild("HumanoidRootPart")
local Hum = script.Parent:WaitForChild("Humanoid")
local sound = HRP:WaitForChild("Running") sound.Volume = 0
local plr = script.Parent
local FootstepEndEvent = game.ReplicatedStorage:WaitForChild("FootstepEnded")
local CanRelease = true
local CanStep = true
local CanBetween = true
local CanHandStep = true
local CanWallStep = true
local CanHandStepRelease = true
local RS = game:GetService("RunService")
local MaxSpeed = 90
local CurrentVolume = 0
local TargetVolume = 0
local head = script.Parent:WaitForChild("Head")
local Wind = script:WaitForChild("Wind")
local ClothAmbient = Wind:WaitForChild("Cloth")
local WindAmbient = Wind:WaitForChild("Wind")
local RaycastParam = RaycastParams.new()
RaycastParam.FilterDescendantsInstances = Char:GetDescendants()
local SoundScript = require(player.PlayerScripts.Modules:WaitForChild("Sounds"))
local SoftMaterials = {Enum.Material.Air, Enum.Material.ForceField, Enum.Material.Neon, Enum.Material.Foil, Enum.Material.Sand, Enum.Material.Glass, Enum.Material.Fabric, Enum.Material.Grass}
game.Players.LocalPlayer.Character.Humanoid.AnimationPlayed:Connect(function(track)
--if track.Name == "RunAnim" or track.Name == "WalkAnim" then
local R
local Folder = HRP.Concrete
local IsSoft = false
track:GetMarkerReachedSignal("Footstep"):Connect(function()
if CanStep == true then
if track.Name == "WallClimb" then
R = workspace:Raycast(HRP.Position, HRP.CFrame.LookVector * 3, RaycastParam)
else
R = workspace:Raycast(HRP.Position, Vector3.new(0,-3.5,0), RaycastParam)
end
if R and R.Instance.Name == "Water" then
Folder = HRP:FindFirstChild("Water")
elseif R then
Folder = HRP:FindFirstChild(string.split(tostring(R.Instance.Material), ".")[3])
if table.find(SoftMaterials, R.Instance.Material) then
IsSoft = true
end
if not Folder then
Folder = HRP.Concrete
end
end
CanStep = false
spawn(function()
CanStep = true
end)
for i,v in pairs(Folder.Step:GetChildren()) do
for i,v2 in pairs(HRP:GetChildren()) do
if v2.Name == v.Name then v2:Destroy() end
end
end
local s = Folder.Step:GetChildren()[math.random(1, #Folder.Step:GetChildren())]:Clone()
--s.Name = "Step"
s.Parent = HRP
s:Play()
SoundScript.PlaySound(s.Name)
s.Ended:Connect(function()
s:Destroy()
end)
end
end)
end)
--[[RS.Heartbeat:Connect(function()
CurrentVolume = CurrentVolume + (TargetVolume - CurrentVolume) * 0.1
--print(CurrentVolume)
local Velocity = HRP.AssemblyLinearVelocity.Magnitude
TargetVolume = (Velocity / MaxSpeed) + 0
ClothAmbient.Volume = CurrentVolume
WindAmbient.Volume = CurrentVolume
if ClothAmbient.Volume >= 2 then ClothAmbient.Volume = 2 end
if WindAmbient.Volume >= 2 then WindAmbient.Volume = 2 end
end)]]
Here’s a video showing the problem:
If anyone could help i would appreciate it, thanks.
Would it be possible if you could provide a stripped-down version of the studio so I can find a solution for your issue? I lack information related to your code to assume a possible solution to your code (please add comments ). The good news is that your detection logic (which I’ve simplified) is functional, and it seems to be related to your setup.
local module = {}
local Player = game.Players.LocalPlayer
local RE = game.ReplicatedStorage.Sounds
function module.PlaySound(Sound, Is2D)
if type(Sound) ~= "string" then
if Is2D == true then
local NewSound = Sound:Clone()
NewSound.Parent = game.SoundService
NewSound:Play()
NewSound.Ended:Wait()
NewSound:Destroy()
else
Sound:Play()
end
end
RE:FireServer(Sound)
end
RE.OnClientEvent:Connect(function(Plr, Sound)
if Player ~= Plr then
Sound:Play()
end
end)
return module
local module = {}
local Player = game.Players.LocalPlayer
local RE = game.ReplicatedStorage.Sounds
function module.PlaySound(Sound, Is2D)
if type(Sound) ~= "string" then
if Is2D == true then
local NewSound = Sound:Clone()
NewSound.Parent = game.SoundService
NewSound:Play()
NewSound.Ended:Wait()
NewSound:Destroy()
else
Sound:Play()
end
end
RE:FireServer(Sound)
end
RE.OnClientEvent:Connect(function(Plr, Sound)
if Player ~= Plr then
Sound:Play()
end
end)
return module