local Player = game.Players.LocalPlayer --local player
repeat wait(1) until Player.Character --repeats wait(1) until the character has loaded
local Character = Player.Character --character
local Breath = game.SoundService.Breath
local Walk = game.SoundService.Walk
local Run = game.SoundService.Run
local Humanoid = Character:FindFirstChild("Humanoid") --finds the humanoid from the players character
local RunService = game:GetService("RunService") --run service
local timer = 0
local function IsPlayerMoving()--function
if Humanoid.MoveDirection.Magnitude >= 30 then--if the movedirection is equal to 30 then the following will happen;
print("Running2")
if timer % 100 == 0 then
print("Running3")
--Run:Play()
timer = 0
end
timer += 1
end
if Humanoid.MoveDirection.Magnitude == 0 then--if the movedirection is equal to 0 then the following will happen;
if timer % 100 == 0 then
Breath:Play()
timer = 0
end
timer += 1
elseif Humanoid.MoveDirection.Magnitude == 16 then
if timer % 60 == 0 then
Walk:Play()
timer = 0
end
timer += 1
end
end
RunService.RenderStepped:Connect(IsPlayerMoving) --running the function
Good evening, as you can see I have a script that checks the speed of the player and under it plays the desired sound. For example, if he stands still, it plays the sound of breathing. If he walks, then the sound of walking. Well, if he runs, then the sound of running. The problem is that when checking the player’s speed at 30. Prints do not work. That is, it seems to ignore this part. Although other checks work. I looked at speed humanoid, and it was equal to 30, but why your prints are not displayed? What’s the problem? If all the checks work after that.
The mistake is that .MoveDirection does not tell you the speed. It only tells you the direction that the player is moving in, hence its magnitude will always be one (it is a unit vector).
You should be using HumanoidRootPart.AssemblyLinearVelocity to get the actual velocity of the player.
Do I have to do it like this? If so, nothing has changed
local Player = game.Players.LocalPlayer --local player
repeat wait(1) until Player.Character --repeats wait(1) until the character has loaded
local Character = Player.Character --character
local Breath = game.SoundService.Breath
local Walk = game.SoundService.Walk
local Run = game.SoundService.Run
local Humanoid = Character:FindFirstChild("Humanoid") --finds the humanoid from the players character
local RunService = game:GetService("RunService") --run service
local timer = 0
local function IsPlayerMoving()--function
if Character.HumanoidRootPart.AssemblyLinearVelocity == 30 then--if the movedirection is equal to 0 then the following will happen;
print("Running2")
if timer % 100 == 0 then
print("Running3")
--Run:Play()
timer = 0
end
timer += 1
end
if Humanoid.MoveDirection.Magnitude == 0 then--if the movedirection is equal to 0 then the following will happen;
if timer % 100 == 0 then
Breath:Play()
timer = 0
end
timer += 1
elseif Humanoid.MoveDirection.Magnitude == 16 then
if timer % 60 == 0 then
Walk:Play()
timer = 0
end
timer += 1
end
end
RunService.RenderStepped:Connect(IsPlayerMoving) --running the function