How would I go on making a global, custom footsteps sound?

  1. What do you want to achieve? I want to achieve a system where when the player walks or jumps, or does anything that produces an action, it activates a sound audible on both the client and server side. For example, I am walking on a sandy object: it produces a sound of sand which can be heard by other clients too, but obviously, within the range.

  2. What is the issue? I don’t know if I should make the script server-side, or if I should make it local, but firing a remote event to the server, playing the sound inside the player humanoidRootPart, but I still don’t know.

I’ve got the script. If it is needed for you to check it, tell me. Thanks in advance!

2 Likes

Why do you need it on the server? You should use remoteevents and fireallclients with the parent of the sound and the id of the sound (along with other properties) and play it only on the clients

You could make it fully client sided by handling other players sounds on your client if they’re within a certain radius from you. Although i don’t know if you can detect animation events on other players walking animations from your own client if youre using animation events to play footstep sounds. So dont expect this to work

1 Like

oh thats a good idea, you can connect an animation keypoint to fireallclients

True but i personally think that footstep sounds and such shouldnt be handled and detected from the server, animations are handled on the client and using fireallclients would delay the sound

no what im saying is, a localscript detects it, fires the server, and fires all clients (just like any other replication)

Also, theres a property under SoundService called ” RespectFilteringEnabled”. You could just enable/disable that and have all of the sounds needed for each footstep material and action inside your character and play them in a local script, everyone will hear it.

Although this will work for every sound being played from the client, not only in your character so it might get annoying

Yeah i think he wants to avoid using remotes since they would have to be called very often

1 Like

How does that work? Would the players listen to the footsteps? Even if it has Max distance and Min distance of hearing it?

I realized this applies to all sounds played locally. This wouldn’t be the case. Are there any other solutions?

Just as it should;
Make every other player simulate footstep sounds locally.
IT LITERALLY DOESNT NEED SERVER BRUH

What do you mean it doesn’t need a server? Are the footsteps sounds playing for everyone, even if called locally? I don’t think you’re understanding. I want the custom footsteps I created to be heard by other players, so it is more realistic.

wow… i think someone doesn’t understand replication

why do you need a replication of footsteps?
You can simulate them on client only.
Unless you are talking about FloorMaterial of course.

What do you mean? Can you all be more specific? I can show you all the script.

local RpS = game:GetService("ReplicatedStorage")
local RS = game:GetService("RunService")
local plrs = game:GetService("Players")

local footsteps = RpS.Footsteps

local plr = plrs.LocalPlayer
local char = script.Parent

local hum = char:WaitForChild("Humanoid")
local HRP = char:WaitForChild("HumanoidRootPart")

local timePosition = 0
local baseStepLength = 10

local distanceFromGround = hum.HipHeight + HRP.Size.Y / 2

local air = Enum.Material.Air

local playing

local getGroundResults = function() : RaycastResult
	local origin = HRP.Position
	local direction = -HRP.CFrame.UpVector * (distanceFromGround + 5)

	local params = RaycastParams.new()
	params.FilterType = Enum.RaycastFilterType.Exclude
	params.FilterDescendantsInstances = {char}

	return workspace:Raycast(origin, direction, params)
end

local getGroundMaterialVariant = function() : string?
	local groundResults = getGroundResults()

	if groundResults then
		local instance = groundResults.Instance

		if not instance:IsA("BasePart") and instance.Transparency < .05 then return end

		return instance.MaterialVariant
	end

	return
end

local getCurrentSong = function() : Sound
	local materialVariant = getGroundMaterialVariant()
	local material = hum.FloorMaterial

	local song = HRP.Air :: Sound

	if material ~= air and materialVariant then
		local songGroup = HRP[material.Name] :: SoundGroup

		song = songGroup:FindFirstChild(materialVariant) :: Sound?
	end

	return song
end

local stopSong = function()
	if playing then
		playing:Stop()

		playing = nil
	end
end

for _, song in HRP:GetChildren() do
	if song:IsA("Sound") then
		song:Destroy()
	end
end

for _, song in footsteps:GetChildren() do
	song:Clone().Parent = HRP
end

RS.Heartbeat:Connect(function(DT)
	local speed = char:GetAttribute("AverageSpeed") or 0

	local moveDirection = hum.MoveDirection
	local isMoving = moveDirection.Magnitude > 0

	local nextSong = getCurrentSong()

	if not nextSong then 
		stopSong(playing)

		return
	end

	if isMoving or nextSong.Name == "Air" then
		local nextLength = nextSong.TimeLength
		local nextTimePos = timePosition % nextLength

		if playing ~= nextSong then
			stopSong()

			playing = nextSong

			playing:Play()

			if nextSong.Name ~= "Air" then
				playing.TimePosition = nextTimePos
			end
		end

		timePosition = playing.TimePosition

		if nextSong.Name ~= "Air" then
			playing.PlaybackSpeed = speed/baseStepLength
		end
	else
		stopSong(playing)
	end
end)

It’s currently on local script as I’ve changed it momentarily.

Make client simulate this sound for other humanoids
I told you that already
You dont need server at all

Yes, though how specifically? I thought we needed server for that? Or are we using FireAllClients?

No?
I see pattern of wrong thinking here so instead:
Make script run locally that plays sound for each humanoid’s footsteps
Server part is at best FloorMaterial replication.
Killing caugh caugh “stable” ping is bad.

Can you produce an example of what you are trying to tell me?

– go through player characters
– bind events to them
– FLOOR METERIAL CHANGED (attribute/remote event doesnt metter how you will check it)!? → CHANGE SOUND ID