I’m trying to make a script that plays a random footstep sound (from a list of 5 that I’ve prepared) when an animation event is triggered, but only if the player doing the animation is touching Terrain (under Workspace). I specifically want the sound to come from the player that’s doing the animation, and make it so everyone can hear each other’s footsteps.
I already have the animations with the events prepared, and verified that they are being triggered. Problem is I don’t know how to script the actual sounds, and asking the AI assistant to write the scripts for me didn’t help much. The scripts it made didn’t work, even after I spent half an hour trying to fix it by describing the errors to the AI.
Yes, I know that, but how do I write the rest of the script? Check for the animation event, check if the player is touching Terrain, randomize the sound, make the sound global, make it come from the player character…?
you could put this script along with the folder containing the sounds in the character you want the sound to play from. Don’t put the script in the folder or it might cause an error.
local hum = (player character):WaitForChild("Humanoid")
local walking = false
local soundList = (soundFolder):GetChildren()
hum.StateChanged:Connect(function(old, new)
if new == Enum.HumanoidStateType.Running then
walking = true
else
walking = false
end
end)
while walking do
if hum.FloorMaterial ~= Enum.Material.Air then
local randomSound = soundList[math.random(1, #soundList)]
randomSound:Play()
task.wait(randomSound.TimeLength)
end
task.wait()
end
if the sounds don’t stop playing with the above script then wrap the while loop in a coroutine.
coroutine.resume(coroutine.create(function()
--loop here
end))