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

How do i change and add default animation for an npc?

I dont want to copy the Animate localscript from a player

I've done sum research on google and couldnt find it out. Im using

if math.floor(npc.HumanoidRootPart.Velocity.Magnitude)>0 then

but animation like default r15 running actually affect the HumanoidRootPart velocity. Others like idle or anything that doesnt move the root part works.

This is what does the code looks like

local animation = {
		idle = npc.Idle,
		run = npc.Run,
		atk = npc.Attack
}


local IdleTrack = npc.Humanoid:LoadAnimation(animation.idle)
local AttackTrack = npc.Humanoid:LoadAnimation(animation.atk)
local RunTrack = npc.Humanoid:LoadAnimation(animation.run)

local animtable = {
	['idle'] = IdleTrack,
	['run'] = RunTrack,
	['atk'] = AttackTrack
}

local animstring = 'idle'

while wait() do
	if not animtable[animstring].isPlaying then
		for i,v in pairs(animtable) do
			if not i == animstring then
				animtable[i]:Stop()
			end
		end

		animtable[animstring]:Play()
		print(animtable[animstring])
	end

	npc.Humanoid:MoveTo(baseunit.Position + Vector3.new(8,0,0))

	for i, entity in pairs(game.ReplicatedStorage.UnitFolder:GetChildren()) do
		if math.floor(npc.HumanoidRootPart.Velocity.Magnitude)>0 then
			animstring = 'run'
		elseif game.Workspace:FindFirstChild(entity.Name) then
			local relativePos = npc.Hitbox.CFrame:pointToObjectSpace(entity.HumanoidRootPart.Position)
			if math.abs(relativePos.X) <= npc.Hitbox.Size.X * 0.8 * 0.5 and math.abs(relativePos.Z) <= npc.Hitbox.Size.Z * 0.8 * 0.5 then
				print(tostring(entity.Name).." is inside")
				animstring = 'atk'
				onHit(1.2)
				task.wait(1.5)
			end
		else
			animstring = 'idle'
			IdleTrack:Play()
		end
	end
end

1 answer

hey you! have you ever heard of enes? if you are in trouble, better call enes!

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