My Footstep system does not work changing playbackspeed

I simply want to make the footsteps sound heard from the server side, but I can’t change the playback speed of the sound depending on the player’s speed.

Here the script in StarterCharacter

local sounds = game:GetService('SoundService')
local runtime = game:GetService('RunService')
local char = script.Parent
local hrp = char:WaitForChild("HumanoidRootPart")
local hum = char:WaitForChild("Humanoid")
local walking

wait(1)
script:WaitForChild('FootstepSounds').Parent = hrp
wait(0.1)
local materials = hrp:WaitForChild("FootstepSounds")

hum.Running:connect(function(speed)
	if speed > hum.WalkSpeed/2 then
		walking = true
	else
		walking = false
	end
end)

function getMaterial()
	local floormat = hum.FloorMaterial
	if not floormat then floormat = 'Air' end
	local matstring = string.split(tostring(floormat),'Enum.Material.')[2]
	local material = matstring
	return material
end

local lastmat
runtime.Heartbeat:connect(function()
	if walking then
		local material = getMaterial()
		if material ~= lastmat and lastmat ~= nil then
			materials[lastmat].Playing = false
		end
		local materialSound = materials[material]
		materialSound.PlaybackSpeed = hum.WalkSpeed/12 -- Here is the problem i guess..
		materialSound.Playing = true
		lastmat = material
	else
		for _,sound in pairs(materials:GetChildren()) do
			sound.Playing = false
		end
	end
end)

Someone can help me pls? :sweat_smile:

1 Like

If you want to replicate client side (like footstep) to server, you’ll have to use RemoteEvent.

I don’t think wait is necessary, if it is use task.wait() instead as wait() is deprecated.

Wouldn’t this always return true? Since the speed parameter is the same as WalkSpeed.