My animation is not playing

Hello, im working on a knife framework. I try to create it myself because it needed to work on NPC’s too and i will code it too after solve my problem.

My problem is about Animation. I got message “ok3” but my animation isn’t playing.

local Anim
local IsAnim, IsEnabled = false, false
local plr = script.Parent.Parent.Parent
script.Parent.Play.OnServerEvent:Connect(function()
	if IsEnabled == true then
		local Anim = plr.Character.Humanoid:LoadAnimation(script.Parent.KnifeAnim)
		if IsAnim == false then
			Anim:Play()
			print("ok3")
			IsAnim = true
			coroutine.wrap(WaitAnimation)()
		elseif IsAnim == true then
			Anim:Stop()
			Anim:Play()
			coroutine.wrap(WaitAnimation)()
		end
	end
end)

function WaitAnimation()
	if Anim ~= nil then
		while Anim.IsPlaying == true do
			wait()
		end
		if Anim.IsPlaying == false then
			IsAnim = false
		end
	end
end

script.Parent.Handle.Touched:Connect(function(hit)
	if hit.Parent:WaitForChild("Humanoid") then
		hit.Parent:WaitForChild("Humanoid"):TakeDamage(hit.Parent:WaitForChild("Humanoid").Health)
	end
end)

script.Parent.Equipped:Connect(function()
	IsEnabled = true
end)

script.Parent.Unequipped:Connect(function()
	IsEnabled = false
end)

Animation property is on action. Not Local Script, Animation ID is valid. I don’t know why i got this problem. “KnifeAnim is an Animation”

Script is hard to read.

script parent = humanoid?
script parent parent = character?
script parent parent parent = player (OK)

Is the animation ID yours? As in, did you publish it personally?

script parent is tool for me.
script parent parent is Player Backpack for me.
script Parent Parent Parent is player.

Animation is created by myself. I tried 2 times.

OK, I think I have enough info… try this change:

local Anim = plr.Character.Humanoid.Animator:LoadAnimation(script.Parent.KnifeAnim)

Animator is something specific do i need to put something? It doesn’t work.

Animator is an object within humanoid. Funny enough I can’t find a way to add one, but I can copy an existing one.

image

1 Like

I think it will work, wait while i prepare my script.

Deprecating LoadAnimation on Humanoid and AnimationController - Updates / Announcements - DevForum | Roblox

Some information for you, apparently the code you wrote used to work, then they added the animator.

I don’t know how can i thank to you, i working with this problem like 1 weeks. I got the main problem but your solution helped too.

1 Like