Loading an Animation problem

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I just want to play the idle animation while the coroutine gets resumed.
  2. What is the issue? Include screenshots / videos if possible!
    loading the Animation does not load and can’t play; it doesn’t give errors in the output too.
    Loading the animation too causes the coroutine to not resume. why’s that?

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
Video example:

the place:
Place_AutoRecovery_2.rbxl (212.7 KB)

edit: if the video does not load you can download this vid:
robloxapp-20210616-0245447.wmv (1.2 MB)

I still have a problem; im confused does anyone know why is it causing it? Also why is it not giving me any error output.

I’m assuming you’re traying to load the animation to a tower model it would be more helpful if you sent the code that’s not working instead of going through your whole game. You need a humanoid to load an animation I believe.

  1. you don’t need a humanoid to load an animation. Animator is all you need;
    –ive read that loading an animation with humanoid is depcrated.
    and the tower is animated with animation controller.

2)i dont have the studio open but i will edit my reply to show you the code.
– Ill try to post the code that is having a problem with loading an animation problem as said in the title.

1 Like
-- MODULESCRIPT CODE --

local module = {} -- notice how this is what a table looks like?


-------------
--\SERVICE\--
-------------
local TS = game:GetService("TweenService")

-----------------------
---this effect functions controls the tower effect aesthetic
--nothing to explain here other than that it just controls
--the tower effect aesthetic.
-----------------------
local function EffectsControl(arguement1,effects)
	effects.Shoot:Play()
	if arguement1 == "Fire" then
		effects.Effect1.MuzzleEffect.Enabled = true
		
		return effects.Effect1.MuzzleEffect
	end
end
-----------------------
---this Animate function controls the tower animation.
--nothing to explain here other than that it just controls
--the tower animation.
-----------------------
local function Animate(hum,Animation,animateId)
	--updates animationid to passed arguement1.
	Animation.AnimationId = animateId
	--loads the new animationId
	local loadanimation = hum:LoadAnimation(Animation)
	loadanimation:Play()
	--sets the global variable to loaded animation.
	return loadanimation
end
-----------------------
---this attack functions controls the attack function
--nothing to explain here other than that it just controls
--how it attacks.
-----------------------
function Attack(model,bullettype,enemy,Base)
	
	local model_stats = model.Stat;
	local Animation = model_stats.Animation;
	local damage = model_stats.Damage;
	
	local hum = model.AnimationController.Animator;
	local effect = model.Weapon.Effects
	local returned_val = EffectsControl("Fire",effect)
	
	local hitbox = Instance.new("Part")
	hitbox.Size = model.Weapon.Size hitbox.CanCollide = false
	--\\
	hitbox.CFrame = CFrame.new(enemy.PrimaryPart.Position,model.PrimaryPart.Position);
	--\\
	hitbox.Position = model.Weapon.Position hitbox.Parent = game.Workspace
	bullettype.BulletMesh:Clone().Parent = hitbox

	model:SetPrimaryPartCFrame(
		CFrame.new(
			model.PrimaryPart.Position,
			Vector3.new(
				enemy.PrimaryPart.Position.X,
				model.PrimaryPart.Position.Y,
				enemy.PrimaryPart.Position.Z
			)
		)
	)
	
	if bullettype.Value == "Fist" or 
		bullettype.Value == "Knife"
	then
		hitbox.Position = model.Weapon.Position
		local weld = Instance.new("Weld")
		weld.Part0 = model.Weapon
		weld.Part1 = hitbox
		weld.Parent = model.Weapon
		
	elseif bullettype.Value == "Bullet" then
		hitbox.Position = model.PrimaryPart.Position
		hitbox.Velocity = model.PrimaryPart.CFrame.LookVector*190
	end
	
	hitbox.Touched:Connect(function(hit)
		if hit.Parent ~= nil 
			and hit.Parent ~= model
			and hit.Parent:FindFirstChild("Stat") ~= nil
			and hit.Parent.Stat.Role.Value ~= Base
		then
			hit.Parent.Stat.Health.Value-=damage.Value
			hitbox:Destroy()
		end
	end)
	Animate(hum,Animation,Animation.ShootAnimation.Value).Stopped:Wait()
	if returned_val ~= nil then
		returned_val.Enabled = false
	end
	hitbox:Destroy()
end
-----------------------
---this move functions controls the tower
--about movements. it will make the tower go
--through each path,
--the model arguement is a arguement that was passed.
-----------------------

function Move(model,Map)
	local position = nil
	local targetPos = 1
	local source = Map.Roads.Road:GetChildren()
	
	local walkspeed = TweenInfo.new(

		model.Stat.Walkspeed.Value,
		Enum.EasingStyle.Sine,
		Enum.EasingDirection.InOut

	)		
	for i, target in pairs(source) do
		if target.Name == tostring(targetPos) then 
			print(target.Name)
			position = target.Position
			break
		end
	end
	
	local walk = TS:Create(
		model.PrimaryPart, 
		walkspeed, 

		{CFrame = 
			CFrame.new(Vector3.new(position.X,position.Y+1.075,position.Z)) * 
			CFrame.Angles(0,math.rad(90),0)
		}
	)
	walk:Play()
	walk.Completed:Connect(function(didArrive)
		if not didArrive then
			warn("not arrive")
		end
		--selects the next target
		targetPos += 1
		if targetPos <= #source then
			Move()
		else
			print("Done moving!")
		end
	end)
	return walk
end
-----------------------
---this action function controls how the tower works
--it will call the 2 function above to depending on what moves.value
--it finds.
--the arguement1 tells wether the tower should move or not
--enemy is a enemy model, another arguement.
--model is the towermodel. enemy and model will be used
--to pass onto another function it will call.
-----------------------

function Actions(arguement1,enemy,model,Map)
	local model_stat = model.Stat
	local bullettype = model_stat:FindFirstChild("BulletType")
	local base = model_stat.Role
	local move = model_stat.Moves
	
	if string.find(move.Value,"Walk") 
		and string.find(move.Value,"Summon")
	then
		Move(model,Map)
	end
	
	if string.find(move.Value,"Attack") then
		Attack(model,bullettype,enemy,base.Value)
	end
end

-----------------------
---this controls the tower finding targets
--nothing to explain here other than that it controls how the tower
--finds the target.
-----------------------
function findTarg(range,cooldown,enemies,towermodel,targettype,Map)
	print("im getting calls")
	local thread = coroutine.create(function()
		print("a new thread.")
		local nearby = {}
		local Map = Map
		local baseFolder = Map[towermodel.Stat.Role.Value]
		local debounce = false
		
		print(Map,baseFolder,debounce)
		
		while wait(cooldown.Value) do
			print("while loops")
			for i, enemy in pairs(enemies:GetChildren()) do
				if (towermodel.PrimaryPart.Position - 
					enemy.PrimaryPart.Position).magnitude <= range.Value 
					and enemy ~= nil
				then
					
					if targettype.Value == "First" then							
						table.remove(nearby, 1)
						table.insert(nearby, enemy)
						--targets enemy in its eyes
					elseif targettype.Value == "Ray" then	
						--creates ray.
						local ray = workspace:FindPartOnRayWithIgnoreList(Ray.new(
							Vector3.new(towermodel.PrimaryPart.Position.X+0.5,								
								towermodel.PrimaryPart.Position.Y,towermodel.PrimaryPart.Position.Z	
							), 
							towermodel.PrimaryPart.CFrame.lookVector * 12), 
							{Map.Roads,baseFolder}
						)
						--indicates that the ray is looking
						--at the enemy.
						if ray ~= nil and ray.Parent == enemy then
							table.remove(nearby, 1)
							table.insert(nearby, enemy)
						end
					end
					if debounce == false then
						Actions(true,nearby[1],towermodel,Map)
					end
				end
			end
			--]]
		end
	end)
	
	return thread
end

function module.Hitman(towermodel,enemyfolder,Map)
	print("YE")
	local stat = towermodel.Stat
	local range = stat.Range
	local cooldown = stat.Cooldown
	local enemies = enemyfolder
	local targettype = stat.targetType
	local hum = towermodel.AnimationController.Animator
	
	local loadanimation = hum:LoadAnimation(stat.Animation.AnimationId)
	loadanimation:Play()
	
	print(range,cooldown,enemies,targettype)
	coroutine.resume(findTarg(range,cooldown,enemies,towermodel,targettype,Map))
	--//loads idle animation first.
	--Animate(stat.Animation.AnimationId)
	print("skips oooo")
end

--[[
local cooldown = stats:FindFirstChild("Cooldown");
		 local damage = stats:FindFirstChild("Damage");
		 local bulletType = stats:FindFirstChild("BulletType");
		 local health = stats:FindFirstChild("Health");
		 local unique = stats:FindFirstChild("Unique")
		 local targettype = stats:FindFirstChild("targetType")
		 local role = stats:FindFirstChild("Role")
		 local range = stats:FindFirstChild("Range")
		local moves = stats:FindFirstChild("Moves")
]]

return module

the error line is in the module.Hitman where i try to load animation and the coroutine doesn’t get resumed.

Turns out i was loading the animation animation Id; but it should just gave me an error. Right? but yeah.