Why is my animation looking weird?

Here from the video, you can see how the animation is being played. Whenever a player is in the distance of the humanoid, the bot will follow the player, but the animations looks weird. Very Weird.

here is the script.


local char = script.Parent
local humanoid = char:WaitForChild('Humanoid')

local walkAnim = script:WaitForChild('WalkAnim')
local walkAnimTrack = humanoid.Animator:LoadAnimation(walkAnim)
local dist = 100


local function findNearestTorso(pos)
	local list = game.Workspace:children()
	local torso = nil
	local temp = nil
	local human = nil
	local temp2 = nil
	for x = 1, #list do
		temp2 = list[x]
		if (temp2.className == "Model") and (temp2 ~= script.Parent) then
			temp = temp2:findFirstChild("Torso")
			human = temp2:findFirstChild("Humanoid")
			if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then
				if (temp.Position - pos).magnitude < dist then
					walkAnimTrack:Play()
					torso = temp
					dist = (temp.Position - pos).magnitude
				elseif (temp.Position - pos).magnitude > dist then
					walkAnimTrack:Stop()
				end
			end
		end
	end
	return torso
end

while true do
	wait(0.1)
	local target = findNearestTorso(script.Parent:WaitForChild('MiddleTorso').Position)
	if target ~= nil then
		script.Parent:WaitForChild('Humanoid'):MoveTo(target.Position, target)			
	end	
end

Note: This is a script from tutorial/tooblox. I just looked at the code, understood what was going on and redid some aspects

Any help is appreciated.

1 Like

You can also see later in the video that I am in range of the bot yet he does not come towards me or play an animation unless i go back and touch him manually. which is not right

You could make a separate script to play the animation when the bot moves. If that’s your target.

Here’s a simple animation script:

    local animation = script:WaitForChild("Animation")
    local humanoid = script.Parent:WaitForChild("Humanoid")
    local AnimPlay = humanoid:LoadAnimation(animation)

humanoid.Running:Connect(function(speed)
	if speed > 0 then
		if not AnimPlay.IsPlaying then
			AnimPlay:Play()
		end
	else
		if AnimPlay.IsPlaying then
		AnimPlay:Stop()
		end
	end
end)
2 Likes

Worked like a charm. thanks again