Playing animation on non player character doesnt work

I want to play a guardbreak animation on the character, it works on players, but not npc’s

It doesnt play, it only stuns them, the animation just doesnt play on them

I tried setting the priortiy to Action4

  function GlobalWeapons.DealPosture(char, posture)
	if char:GetAttribute("Stunned") then return end
	char:SetAttribute("Posture", math.clamp(char:GetAttribute("Posture") + posture,0, 100))
	--print(char:GetAttribute("Posture"))
	if char:GetAttribute("Posture") == 100 then
		
		char:SetAttribute("Stunned", true)
		char:SetAttribute("Posture", 4)
		local gbtrack = char.Humanoid:LoadAnimation(animations.GuardBreak)
		char:SetAttribute("cancel", true)
		gbtrack.Priority = Enum.AnimationPriority.Action4
		gbtrack:Play()
		print(char, "guard break")
		task.wait(2.5)
		gbtrack:Stop()
		char:SetAttribute("Stunned", false)
	end
end

it does print Rig guard break, i also tried loading it onto the Animator but no change

this is the idle animation, but i dont think it should be problem since its lower priority.

if npc then
			local animType = weaponInfo[weapon] and weaponInfo[weapon].AnimateType or 1
			local humanoid = wielder:FindFirstChild("Humanoid")
			game.StarterPack[weapon]:Clone().Parent = wielder
			if animType == 1 and animations.Weapons[weapon] then
				wielder:SetAttribute("Katana", true)

				-- Play the equip animation
				local equipTrack = humanoid:LoadAnimation(animations.Weapons[weapon].Equip)
				equipTrack.Priority = Enum.AnimationPriority.Action
				equipTrack.Looped = false
				equipTrack:Play()

				-- Update idle/walk only after the equip finishes
				equipTrack.Stopped:Connect(function()
					-- Destroy the equip track
					equipTrack:Destroy()

					-- Update idle/walk animations
					local wAnims = animations.Weapons[weapon]
					if wielder:FindFirstChild("Animate") then
						wielder.Animate.idle.Animation1.AnimationId = wAnims.Idle.AnimationId
						wielder.Animate.idle.Animation2.AnimationId = wAnims.Idle.AnimationId
						wielder.Animate.run.RunAnim.AnimationId = wAnims.Walk.AnimationId
						wielder.Animate.walk.WalkAnim.AnimationId = wAnims.Walk.AnimationId

						-- Briefly disable/re-enable Animate to apply changes
						wielder.Animate.Enabled = false
						task.wait(0.03) -- tiny delay to ensure changes apply
						wielder.Animate.Enabled = true
					end
				end)


			elseif animType == 2 and humanoid and animations.Weapons[weapon].Equip then
				local track = humanoid:LoadAnimation(animations.Weapons[weapon].Equip)
				track:Play()
				track.Looped = false
				track.Stopped:Connect(function()
					track:Destroy()
					if animations.Weapons[weapon].Idle then
						local idleTrack = humanoid:LoadAnimation(animations.Weapons[weapon].Idle)
						idleTrack.Priority = Enum.AnimationPriority.Action
						idleTrack:Play()
						idleTrack.Looped = true
					end
				end)
			end
		end

any help is appreciated

4 Likes

This is a local-script ? (Make it server-side script and because this isn’t client, however your choice)

Honestly you could just make it display on clients, instead on server

Because of server-side animation that will make animation laggy (because replication is sended in between time to clients)

no, both are server, so instead of playing the animation from server, i just send event to all clients to play that animation on the npc?

Weird, i had seen someone having the Server-side humanoid having animation and working

Althought yes by sending who is that Model and what animation should play it

1 Like

Yes, all animations of the npc are server-side, only this function just doesnt play it for them, when i put the guardbreak animation for example instead of sword swing, it works, which i find strange.

I tried that, but there was no difference

Is the NPC’s rig correctly adjusted for the animation and are the properties of the NPC correctly adjusted so that there is no interference with the animations?

I notice for example you stun the NPC quite a bit, make sure that this attribution isn’t interfering with the animation.

There is likely some sort of interference with the animation itself and not a runtime code error or something of that sort given the output still prints “guard break” as you’ve already mentioned prior.

strange, there shouldnt be anything interfering since npc’s and players share majority of functions for the animations

Try Anchoring the HumanoidRootPart, if this does not work, try this.

for i, track in Humanoid:GetPlayingAnimationTracks() do
	track:Stop()
end
-- Play animation here.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.