I’m a beginner to scripting, and was recently trying to create a local script that plays a footstep sound whenever an animation event is reached in my player’s custom run and walk animations.
In StarterCharacterScripts, my R6 character has a modified animate script with a custom walk animation and also has a runHandler local script that plays a run animation whenever the player runs.
I attempted to make another local script that played a footstep sound whenever a animation event was reached in either the walk or run animation. However, it is not working due to (im assuming) the run animation and walk animation being played in different local scripts.
Is there any way I could remedy this issue? I wanted to keep all the footstep related code in a separate local script from the run and walk scripts, if it is possible.
2 Likes
If you simply want to replace the default footstep audio, put this file into StarterPlayerScripts and change the 2 strings labelled Running to whatever your audio id is, i put comments where you should put the ids:
RbxCharacterSounds.rbxm (9.8 KB)
so like basically when you actually run any game on roblox, it creates 3 files in starter player scripts, 1 of which handles sounds made by a player.
The file I attached is literally just that RbxCharacterSounds script but with 2 extra comments to show you what to replace. By having a script that is the same name as one of these 3 default starterplayerscripts it just causes the default script to not load in meaning you essentially just replace the default script with your own.
1 Like
Here’s some code example, It won’t work, but it’s a general idea.. Your just listening for the getmarkerreachedsignal then checking if it has the right name and then playing the footstep sound. I hope this helps you.
local function connectFootstepMarkers(animationTrack)
if not animationTrack then return end
local markerSignal = animationTrack:GetMarkerReachedSignal(FOOTSTEP_MARKER_NAME)
markerSignal:Connect(function(param)
footstepSound:Play()
end)
end
An alternative to this is removing the “Running” sound in HumanoidRootPart & adding your own tied to the animate script.
Something like
local players = game:GetService("Players")
local materialModule = require(script.Module)
-- removes the existing footstep sound without modifying the existing character scripts
local function onPlayerAdded(player)
local function onCharacterAdded(character)
local root = character:WaitForChild("HumanoidRootPart")
repeat task.wait() until root.Running
if root.Running then
root.Running:Destroy()
end
local footstep = Instance.new("Sound", root)
footstep.Name == "Footstep"
end
player.CharacterAdded:Connect(onCharacterAdded)
end
players.PlayerAdded:Connect(onPlayerAdded)
-- creates a new sound
local function onFootstep(player, material)
local footstep = player.Character:FindFirstChild("HumanoidRootPart"):FindFirstChild("Footstep")
footstep.SoundId = materialModule[material].Id
footstep.Volume = materialModule[material].Volume
-- any other modifiers like playback speed
footstep:Play()
end
event.OnServerEvent:Connect(onFootstep) -- can be changed to reference a different trigger
I have something similar to this in one of my games. But instead of playing the sound, it leaves behind footprints
This is just the general framework, for optimization, the event would be triggered by the player locally & then sent to the server which would then send it back only to nearby clients by checking Magnitude between root parts. This is so that players not close don’t waste processing replicating the steps and the server doesn’t waste processing either.