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

Animation doesn't play but everything else works?

I'm trying to make npcs walk to parts, which works, but when I try to play the animation it doesn't work, does anyone have a fix?

while wait(0.25) do
script.Parent:MoveTo(game.Workspace.Path.Part3.Position)
	script.Parent.MoveToFinished:Wait()
	script.Parent:MoveTo(game.Workspace.Path.Part1.Position)
	script.Parent.MoveToFinished:Wait()
	script.Parent:MoveTo(game.Workspace.Path.Part4.Position)
	script.Parent.MoveToFinished:Wait()
	script.Parent:MoveTo(game.Workspace.Path.Part2.Position)
end

	local anim = script.Parent:LoadAnimation(script.Parent.Animation)
	anim:Play()

1 answer

✓ Accepted answer

ANSWER: You put your while loop first so any code outside of the while loop will not run until the while loop has finished. (And your while loop never ends, therefore you never get to line 11 and 12.

FIX:

local anim = script.Parent:LoadAnimation(script.Parent.Animation)
anim:Play()

while wait(0.25) do
script.Parent:MoveTo(game.Workspace.Path.Part3.Position)
	script.Parent.MoveToFinished:Wait()
	script.Parent:MoveTo(game.Workspace.Path.Part1.Position)
	script.Parent.MoveToFinished:Wait()
	script.Parent:MoveTo(game.Workspace.Path.Part4.Position)
	script.Parent.MoveToFinished:Wait()
	script.Parent:MoveTo(game.Workspace.Path.Part2.Position)
end

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