Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Animation: My model plays the animation but it doesn't move from it's position?

I created a model called Golem and I rigged it correctly (I'm pretty sure) and I made an animation for it which is just a basic walking animation. I am using most of the scripts and values that can be found in the AI Enemy model in the tool box. I modified the follow script so that it played my animation when it moved. The issue is that the Golem doesn't move. I know for a fact that it is running through he line of code that tells it to move with no error since no errors pop up and because it runs the next lines. I did a compared this version of the Golem to an earlier one I made that moves without the animation (and the earlier version does move, it just doesn't have the animation which means that the animation is causing the problem) and the only difference I found was that the Golem that moved had it's Root Part property set to Torso and the one that doesn't move yet plays the animation has it's Root Part property set to HumanoidRootPart (The Root Part property is in the Humanoid object in the Model). Here is my code that tells it to follow:

`local larm = script.Parent:FindFirstChild("Left Arm")
local rarm = script.Parent:FindFirstChild("Right Arm")
local isplaying = false
local GolemWalkAnim = game.Workspace.GolemWalk
local animTrack = script.Parent.Enemy:LoadAnimation(GolemWalkAnim)

function findNearestTorso(pos)
	local list = game.Workspace:children()
	local torso = nil
	local dist = 20
	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
					torso = temp
					dist = (temp.Position - pos).magnitude
				end
			end
		end
	end
	return torso
end

function walk()
if isplaying == false then
		animTrack:Play()
		isplaying = true
		AnimationCooldown()
	end
end

function AnimationCooldown()
	wait(1.1)
	isplaying = false
end

while true do
	wait(0.1)
	local target = findNearestTorso(script.Parent.Torso.Position)
	if target ~= nil then
		script.Parent.Enemy:MoveTo(target.Position)
		animTrack:Play()
		walk()
	end
end

I copied this code and put it into the follow script in the other Golem (the one without the animation but it moves) and it still moved but it just didn't play the animation (I'm guessing it didn't play the animation because it wasn't rigged. It also doesn't have a HumanoidRootPart) So my final question is, what am I doing wrong? My goal is to make an enemy named Golem that follows the closest player and plays a walking animation while its following that player. Sorry for the long post but I wanted to be as detailed as possible.

5 comments

0

Please put your code in a code block, i'm having trouble reading it.

0

put code in the lines after u press the lua button

0

Ok I put it in lines

0

if it doesn't have a root part and is rigged correctly you could use a AnimationController

0

^ and load the animation into the controller

1 answer

remove the ` in the very first line of the script in the beginning

This discussion is preserved as it was. New answers, comments, and votes are closed.