Yes, in that case you must change your code again, but I provide a valid solution to your initial question. Try this new code:
local Players = game:GetService("Players")
local runAnimation = Instance.new("Animation")
runAnimation.AnimationId = "rbxassetid://891636393"
Players.PlayerAdded:Connect(function(plr)
local character = plr.Character or plr.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local rootPart = character:WaitForChild("HumanoidRootPart")
local runAnimationTrack = humanoid:LoadAnimation(runAnimation)
humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
print(rootPart.Velocity.Magnitude)
if rootPart.Velocity.Magnitude > 25 then
--Run Animation
if not runAnimationTrack.IsPlaying then
print("Animated")
runAnimationTrack:Play(0.1)
end
else
runAnimationTrack:Stop()
print("stop")
end
end)
end)
This this new code, it detect whey the player stop and when he moves also play animation. Is not ideal to use server code for this.
local Players = game:GetService("Players")
local runAnimation = Instance.new("Animation")
runAnimation.AnimationId = "rbxassetid://16754777947"
Players.PlayerAdded:Connect(function(plr)
local character = plr.Character or plr.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local rootPart = character:WaitForChild("HumanoidRootPart")
local runAnimationTrack = humanoid:LoadAnimation(runAnimation)
humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
end)
local lastMoveDirection = humanoid.MoveDirection
humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
local newMoveDirection = humanoid.MoveDirection
-- Check if the player stopped moving
if lastMoveDirection ~= Vector3.new() and newMoveDirection == Vector3.new() then
local currentVelocity = rootPart.Velocity.Magnitude
runAnimationTrack:Stop()
end
lastMoveDirection = newMoveDirection
end)
----------------------------------------------
humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
print(rootPart.Velocity.Magnitude)
local moveDirection = humanoid.MoveDirection
if moveDirection ~= Vector3.new() and rootPart.Velocity.Magnitude >= 24 then
if not runAnimationTrack.IsPlaying then
print("Animated")
runAnimationTrack:Play(1)
end
end
end)
end)
Alright, the code and animation works, but for one thing. The default walk animation of the character kinda overrides the running animation. I tested this out by using my idle animation that is obviously different from the default walking animation, and saw that some parts of both animations were playing(Such as a hand moving right while walking, which are two different animations blended into one) So the code works fine, it’s just an animation overlap issue. There’s probably an easy fix, I just don’t really know how.
Didn’t seem to help, I’ll try to figure out how to fix this, because it’s probably an easy fix. If I can’t find anything, I’ll reply. Thanks for the help though, really appreciated.