I have an NPC that moves around and attacks players in a certain radius, but how would I make it so it has animations? For now, it just walks around without animating.

Script:

local MTorso = script.Parent.Torso
local MHum = script.Parent.Humanoid

local function find()
	local distance = 100
	local target = nil
	
	for i, v in pairs(game.Workspace:GetChildren()) do
		local torso = v:FindFirstChild("Torso")
		local hum = v:FindFirstChild("Humanoid")
		if torso and hum and v ~= script.Parent then
			if (MTorso.Position - torso.Position).magnitude < distance then
				distance = (MTorso.Position - torso.Position).magnitude
				target = torso
			end
		end
	end
	return target
end
while wait(1) do
	local torso = find()
	if torso then
		MHum:MoveTo(torso.Position)
	else
		MHum:MoveTo(MTorso.Position + Vector3.new(math.random(-50, 50), 0, math.random(-50, 50)))
	end
end

Thanks for your help!

1 comment

0

If your NPC is R6, then get an R6 animation script and put inside the NPC but you must change the LocalScript to a ServerScript, it's the same for R15 also. The animation script is in your character when you play the game.