Need help playing an animation when the walkspeed is 30 and the player moves

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? I have a custom StarterCharacter model that I made a running animation for. I’m trying to have it play only when the walkspeed of the player is 30, and only when they move.

  2. What is the issue? I just can’t seem to figure out how.

  3. What solutions have you tried so far? I’ve tried Discord, but either was ignored or told to read the forums, but those got me no where.

wait(2)

local LocalPlayer = game.Players.LocalPlayer
local Sprint = game.Workspace.Sprint
local humanoid = game.Players.LocalPlayer.Character.Humanoid
local myChar = game.Players.LocalPlayer.Character or game.Player.LocalPlayer.CharacterAdded:wait()
local humanoid = myChar:WaitForChild("Humanoid")

local Sprintplay = LocalPlayer.Character.Humanoid:LoadAnimation(Sprint)
Sprintplay.Priority = Enum.AnimationPriority.Movement

if humanoid.WalkSpeed == 30 then
    humanoid.StateChanged:Connect(function(oldState, newState)
    if newState == Enum.HumanoidStateType.Running then
        print("running")
        Sprintplay:Play()
    end
end)
end

I’ve also tried this

wait(2)

local LocalPlayer = game.Players.LocalPlayer
local Sprint = game.Workspace.Sprint
local Idle = game.Workspace.Idle
local humanoid = game.Players.LocalPlayer.Character.Humanoid
local myChar = game.Players.LocalPlayer.Character or game.Player.LocalPlayer.CharacterAdded:wait()
local humanoid = myChar:WaitForChild("Humanoid")

local Sprintplay = LocalPlayer.Character.Humanoid:LoadAnimation(Sprint)
Sprintplay.Priority = Enum.AnimationPriority.Movement
local Idleplay = LocalPlayer.Character.Humanoid:LoadAnimation(Idle)

if humanoid.WalkSpeed == 30 then
	local MV = LocalPlayer.Character.Humanoid.MoveDirection
	if LocalPlayer.Character.Humanoid.MoveDirection == Vector3.new(0,0,0) then

    Sprintplay:Stop()
    Idleplay:Play()    
end


    if LocalPlayer.Character.Humanoid.MoveDirection ~= Vector3.new(0,0,0) then
    if Sprintplay.IsPlaying ~= true then
    
    Idleplay:Stop()
    
    Sprintplay:Play()
    end
end

LocalPlayer.Character.Humanoid:GetPropertyChangedSignal("MoveDirection"):Wait()
end
1 Like

You only check for the walkspeed once, you could do this:

humanoid.Changed:connect(function()
if humanoid.WalkSpeed == 30 then
	if humanoid.MoveDirection == Vector3.new(0,0,0) then
    Sprintplay:Stop()
    Idleplay:Play()    
    end
end
end)

In addition to that, you should use

humanoid:GetPropertyChangedSignal("WalkSpeed"):Connect(function()

instead of

humanoid.Changed:connect(function()

I tried this so that the Sprintplay would stop once the player stops walking, but now it doesn’t play at all hhh

humanoid:GetPropertyChangedSignal("WalkSpeed"):Connect(function()
if humanoid.WalkSpeed == 30 then
	if humanoid.MoveDirection == Vector3.new(0,0,0) then 
		Sprintplay:Stop()
		Idleplay:Play()
	end
	if humanoid.MoveDirection == Vector3.new(0,0,0) then
		if Idleplay.IsPlaying ~= true then
			Sprintplay:Play()
			Idleplay:Stop()
		end
	end
end
end)```
1 Like

You are using 2 if statements to check for the same thing, maybe this will work:

Changed Code
humanoid:GetPropertyChangedSignal("WalkSpeed"):Connect(function()
if humanoid.WalkSpeed == 30 and humanoid.MoveDirection == Vector3.new(0,0,0) then
	Sprintplay:Stop()
	Idleplay:Play()
else 
	Idleplay:Stop()
	Sprintplay:Play()
end
end)
1 Like