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

[Unanswered]The NPC's Animation isn't loading in?

K, so when you approach the NPC's the come towards you, but the animations isnt loading it, and eventually when they swing, it just stops moving.

I've tried basically everything to load in the animation, any help?

Not sure if its the Content Provider area, but the walking is animation is from ROBLOX, and I have it looped. So it should've been working.

local humanoid = script.Parent:WaitForChild("Humanoid")
local torso = script.Parent:WaitForChild("Torso")
local head = script.Parent:WaitForChild("Head2")
local real_head = script.Parent:WaitForChild("Head")
local linked_sword = script.Parent:WaitForChild("Linked_Sword")
local settings = script.Parent:WaitForChild("Settings")
local events = {}
local damage_sounds = {181268610,181268607,181268605}
local hats = {}


--- animations storage ---
local animation_walk = Instance.new("Animation")
animation_walk.AnimationId = "http://www.roblox.com/asset/?id=180426354"
local running_animation_walk = nil

local animation_attack = Instance.new("Animation")
animation_attack.AnimationId = "http://www.roblox.com/asset/?id=1873619820"
local running_animation_attack = nil

--------------------------




function load_hat(id)
local new_hat = game:GetService("InsertService"):LoadAsset(id)
	for i,v in ipairs(new_hat:GetChildren()) do
		if(v.ClassName == "Hat") then
		v.Parent = script.Parent
		end
	end
new_hat:Destroy()
end


Instance.new("ForceField",script.Parent)
--load_hat(hats[math.random(1,#hats)])
	for i = 1,2 do
	wait(0.5)
	humanoid.MaxHealth = settings.Health.Value
	humanoid.Health = settings.Health.Value
	end
script.Parent.ForceField:Destroy()
humanoid.MaxHealth = settings.Health.Value
humanoid.Health = settings.Health.Value




function sound(id,parent,pitch,volume,remove_time)
local sounde = Instance.new("Sound",parent)
game.Debris:AddItem(sounde,remove_time)
sounde.SoundId = "http://www.roblox.com/asset/?id=" .. id
game:GetService("ContentProvider"):Preload(sounde.SoundId)
sounde.Pitch = pitch
sounde.Volume = volume
sounde:Play()
return (sounde)
end





function hurt (human)
	if(human) then
		if(human.Health ~= 0 and human.Parent:FindFirstChild("Torso")) then
		human.Health = human.Health - settings.Damage.Value
		local random_sound_effect = damage_sounds[math.random(1,#damage_sounds)]
		sound(random_sound_effect,human.Parent.Torso,math.random(70,100)/100,1,2)
		end
	end
end




function attack (human)
game:GetService("ContentProvider"):Preload("http://www.roblox.com/asset/?id=94161088")
sound(181268614,linked_sword.Handle,math.random(90,110)/100,1,2)
	if(running_animation_attack == nil and human.Health ~= 0) then
	local event_keyframe_reached
	running_animation_attack = humanoid:LoadAnimation(animation_attack)
	running_animation_attack:Play()
		event_keyframe_reached = running_animation_attack.KeyframeReached:connect(function(keyframeName) -- Bind function to KeyframeReached event
			if (keyframeName == "Hit") then
			hurt(human)
			
			elseif(keyframeName == "End") then
			running_animation_attack:Stop()
			running_animation_attack = nil
			event_keyframe_reached:disconnect()
			end
		end)
	
	repeat wait(0.05) until running_animation_attack == nil
	end
end




function walk(operation)
game:GetService("ContentProvider"):Preload("http://www.roblox.com/asset/?id=180426354")
	if(operation == true and running_animation_walk == nil) then
	running_animation_walk = humanoid:LoadAnimation(animation_walk)
	running_animation_walk:Play()
	
	
	elseif(operation == false and running_animation_walk ~= nil) then
	running_animation_walk:Stop()
	running_animation_walk = nil
	humanoid:MoveTo(torso.Position,torso)
	end
end

----------Everything else below was basically irrelevant to the loading of the animation-----

function follow(plr,char,dist)
	if(plr and char) then
		if(dist <= settings.Attack_Distance.Value and char:FindFirstChild("Humanoid")) then
		walk(false)
		attack(char.Humanoid)
		
		
		elseif(char:FindFirstChild("Humanoid") and dist > settings.Attack_Distance.Value) then
		walk(true)
		script.Parent.Humanoid:MoveTo(char.HumanoidRootPart.Position,char.HumanoidRootPart)
		end
	
	else
	walk(false)
	end
end

1 answer

Hey I think I have the answer, I have ran into this problem a lot, make sure you are using an animation that you made or if you are making a group game that its a group animation.

1 comment

0

That isnt the case, the animations are from ROBLOX, and works in an ordinary NPC

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