How do i make when a boss finishes attack he has a resting anim?

When the boss stops attacking i want him to have like a resting idle so the players can attack the boss

Here is the half of the script

	while wait(5) do
		if monster.Humanoid.Health > 0 then
			monster.ForceField.Visible = true
			
			HammerChallenge()
			SpikeChallenge()
			fireBallChallenge()
			lavaChallenge()
		


			
			print("Forcefield has been disabled!")
			monster.ForceField.Visible = false
		else
			break
		end
	end
``
1 Like

Just do

Boss.Humanoid:LoadAnimation("Idle animation Name"):Play()

doesn’t work it says “unable to cast value”

This doesn’t solve your issue, I don’t quite understand what you want. Underneath this is code block is a relevant question though.

You shouldn’t put your wait in the condition of the loop. It would be better to just use it inside of the loop. You are breaking if the condition of the if statement is false, which is what the condition part of the while loop is supposed to be used for.

while monster.Humanoid.Health > 0 do
			monster.ForceField.Visible = true
			
			HammerChallenge()
			SpikeChallenge()
			fireBallChallenge()
			lavaChallenge()
		


			
			print("Forcefield has been disabled!")
			monster.ForceField.Visible = false
            wait(5) 
	end

But as for the actual issue, do you have an animation you want to play specifically that you can’t figure out how to load on the boss? And if so, where in explorer is it?

Do you have your animation parented to the boss?

Ill add the animation in workspace

I dont think i have the animation parented to the boss

monster.Humanoid.HealthChanged:Connect(function() -- instead of looping, just detect when the monster's health changes (to save on performance)
    if monster.Humanoid.Health > 0 then
        -- do stuff here

        -- play the animation:
        local animObj = Instance.new("Animation") -- creates a new animation instance
        animObj.AnimationId = "rbxassetid://" .. 0000 -- the 0's represent the animation id (replace this with your animation id)

        local animation = monster.Humanoid:LoadAnimation(animObj) -- create a new animation track
        animation:Play() -- play the animation

        -- do stuff here
    end
end)

Also, is the monster a custom rig or is it a Roblox Rig?

Then put it in there and then do this

while wait(5) do
	if monster.Humanoid.Health > 0 then
		monster.ForceField.Visible = true
		
		HammerChallenge()
		SpikeChallenge()
		fireBallChallenge()
		lavaChallenge()
	


		
		print("Forcefield has been disabled!")
		monster.ForceField.Visible = false

        local animation = monster.animation name
        monster.Humanoid:LoadAnimation(animation):Play()
	else
		break
	end
end

it works but the thing is it only lasts a few seconds
i need it to last until the next attack begins

how do i make it so that the anim last until the boss attacks again?

You have to code when the boss is going to attack again, but just set the animation variable outside of the scope

local animation

monster.Humanoid.HealthChanged:Connect(function()
    if monster.Humanoid.Health > 0 then
        -- do stuff here

        -- play the animation:
        local animObj = Instance.new("Animation")
        animObj.AnimationId = "rbxassetid://" .. 0000 -- replace this with your animation id

        animation = monster.Humanoid:LoadAnimation(animObj) -- create a new animation track
        animation:Play() 

        -- do stuff here
    end
end)

-- do stuff the detect when the boss is going to attack again
animation:Stop() -- stop the animation

There is an error

monster.Humanoid.HealthChanged:Connect(function()
		if monster.Humanoid.Health > 0 then
			HammerChallenge()
			lavaChallenge()
			SpikeChallenge()
			fireBallChallenge()
			-- play the animation:
			local animObj = Instance.new("Animation")
			animObj.AnimationId = "rbxassetid://" .. 6309496859 -- replace this with your animation id
			animation = monster.Humanoid:LoadAnimation(animObj) -- create a new animation track
			animation:Play() 

			-- do stuff here
		end
	end)
	
	-- do stuff the detect when the boss is going to attack again
	wait(10)
	animation:Stop() -- stop the animation

animation doesn’t get defined until the boss takes damage

You have to make a system that does something and then check there

Event.Event:Connect(function() -- example event
   if animation then -- checks if it's defined
       animation:Stop() -- stops it
   end
end)

also, keep local animation at the top, it’s an upvalue that would function better than making it a global

Also, keep in mind that if the boss has a forcefield (whether it’s visible or not) it would not take damage from Humanoid:TakeDamage

So where do i put that part???

anywhere after local animation is put, just plug it in somewhere that fits in your code

Unknown global event? what should i do? Event

The event was an example of how to use it, you have to code the actual system as I can’t do it

Detects when the boss takes damage
     Plays the animation

Make the boss attack again
     Stop the animation

If your system doesn’t use events then do this

local event = Instance.new("BindableEvent")
local animation

-- rest of the script

event.Event:Connect(function()
   if animation then
       animation:Stop()
   end
end)

-- stuff that makes the boss attack again
event:Fire() -- this would fire the event when the scripts makes the boss attack again to stop the animation

so basically like this?

local event = Instance.new("BindableEvent")
	local animation

	-- rest of the script

	event.Event:Connect(function()
		if animation then
			monster.Humanoid.HealthChanged:Connect(function()
				if monster.Humanoid.Health > 0 then
					HammerChallenge()
					lavaChallenge()
					SpikeChallenge()
					fireBallChallenge()
					-- play the animation:
					local animObj = Instance.new("Animation")
					animObj.AnimationId = "rbxassetid://" .. 6309496859 -- replace this with your animation id
					animation = monster.Humanoid:LoadAnimation(animObj) -- create a new animation track
					animation:Play() 

				end
			end)

			-- do stuff the detect when the boss is going to attack again
			wait(10)
			animation:Stop() -- stop the animation
		end
	end)

No, put the HealthChanged event outside of it, it would only fire when the the main event fires

Did you finish the original script? If so, can I see it so I can show you lol