# How can I detect how fast a player is moving

Hello, I am trying to detect how fast the player is moving then translate that to a footstep sound playback speed.
So what I mean is if the player is moving lets say 4 or very slow play the sound at 0.4 how can I achieve this?

2 Likes

You can try to measure the velocity of the player’s feet.

``````local MAX_VOLUME = 1
local footVelocity = foot:GetVelocityAtPosition(foot.Position)
local volume = math.min(footVelocity.Magnitude / 10, maxVolume)
``````
2 Likes

im using r6 so would I use the players leg instead of their foot?

Actually it works thanks alot!

2 Likes
``````while wait() do
local MAX_VOLUME = 1
local footVelocity = game.Players.LocalPlayer.Character.HumanoidRootPart:GetVelocityAtPosition(game.Players.LocalPlayer.Character.HumanoidRootPart.Position)
local volume = math.min(footVelocity.Magnitude / 10, MAX_VOLUME)

print(tostring(volume))
end
``````

Yes, you can get the velocity at the bottom of the player’s leg.

``````local footVelocity = foot:GetVelocityAtPosition(
leg.CFrame:PointToWorldSpace(
Vector3.new(0, -leg.Size.Y / 2, 0)
)
)
``````

wait one question. how can I return the value of volume and use inside another script I try to do this.

``````local volume = nil

while wait() do
local MAX_VOLUME = 1
local footVelocity = game.Players.LocalPlayer.Character.HumanoidRootPart:GetVelocityAtPosition(game.Players.LocalPlayer.Character.HumanoidRootPart.Position)
local volume = math.min(footVelocity.Magnitude / 10, MAX_VOLUME)

return volume
end
``````

but it just says volume is nil

what do you mean by read? No I can not use it in another function it will just return an error.

This code will not work, cause you need to do something with the volume instead of returning it. Try setting your sound object’s Volume property to volume `sound.Volume = volume`. Then you can just read that volume in other scripts (`local volume = sound.Volume`).

what if I make a new local variable outside. Set that new variable = to volume then return the new variable?

Yeah nvm it works I made a new variable set it to volume then returned it

thanks to @Brickman808
Yep so I got it all working I just used this:

``````local movementSpeedMultiplier = nil

spawn(function()
movementController.runService.RenderStepped:Connect(function()
wait()
local MAX_VOLUME = 1
local footVelocity = game.Players.LocalPlayer.Character.HumanoidRootPart:GetVelocityAtPosition(game.Players.LocalPlayer.Character.HumanoidRootPart.Position)
local volume = math.min(footVelocity.Magnitude / 10, MAX_VOLUME)

movementSpeedMultiplier = volume

return movementSpeedMultiplier
end)
end)
``````
1 Like