What I’m attempting to achieve
I have a tool/weapon that has an idle animation, and I’m trying to make it so that the idle animation plays whenever my character isn’t moving.
ISSUE
The idle animation plays when I equip the weapon, but after I walk or run, the idle animation doesn’t play until I re-equip the tool. I tried to modify the script with a ‘renderstepped’ function, but it still doesn’t seem to work.
This is the part of the script that doesn’t work:
RunService.RenderStepped:Connect(function()
local humanoid = character:FindFirstChildOfClass("Humanoid") or character:FindFirstChildOfClass("AnimationController")
local animator = humanoid:FindFirstChildOfClass("Animator")
if humanoid.MoveDirection.Magnitude > 0 then
if track then
track:stop()
if humanoid.MoveDirection == Vector3.new(0,0,0) then
for i,v in ipairs(animator:GetPlayingAnimationTracks()) do
v:Stop()
track:play()
end
end
end
end
end)
Add some print statements to see where in the code it is not working… sorry your video clip doesnt load for me, nothing happens when i try to click that blue link.
You’re checking if MoveDirection.Magnitude == 0 within the check to see if MoveDirection.Magnitude > 0. It’s either one, or the other.
Swap your code to this and let me know if it works.
RunService.RenderStepped:Connect(function()
local humanoid = character:FindFirstChildOfClass("Humanoid") or character:FindFirstChildOfClass("AnimationController")
local animator = humanoid:FindFirstChildOfClass("Animator")
if humanoid.MoveDirection.Magnitude > 0 and track.IsPlaying then
track:Stop()
elseif humanoid.MoveDirection.Magnitude == 0 and not track.IsPlaying then
for i,v in ipairs(animator:GetPlayingAnimationTracks()) do
v:Stop()
end
track:Play()
end
end)