Playing animation not working

This?
image

yeah… is that how it looks in game?? the tool is supposed to be in the backpack but it’s not there

image
Now it is, for some reason it just took a bit to load in.

what happens if punch script becomes a local script instead of server script? with the new code
I’m trying to think of everything atp

Nope, same issue. No errors, but no animations. Still prints the debug.

Okay can you try just like… using a different, basic animation and like reload roblox studio completely before the retest?

Sure… Should I make the animation or find it in toolbox?

Literally anything basic, so I guess make it if youre using roblox anim editor or if youre using moon use one of those built ins


So I made this, and I closed roblox studio and re-opened it, pasted the new ids in the animation, and tried again didnt work, same issue.

I’m not sure if the old way of loading and playing animations has been deprecated, but I believe now you’re meant to use Animator instead of Humanoid.

The first code sample:

local function playAnimationFromServer(character, animation)
	local humanoid = character:FindFirstChildOfClass("Humanoid")
	if humanoid then
		-- need to use animation object for server access
		local animator = humanoid:FindFirstChildOfClass("Animator")
		if animator then
			local animationTrack = animator:LoadAnimation(animation)
			animationTrack:Play()
			return animationTrack
		end
	end
end

local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://507765644"

local character = script.Parent

playAnimationFromServer(character, animation)

Here are some of my possible solutions:

  1. Make sure the animation id property isn’t empty.

If that isn’t the problem than try this on one of your lines of code:

local Humanoid = Character:FindFirstChildWhichIsA("Humanoid")

my solutions:

  • don’t use the Humanoid to play animations, use the Animator instead
  • on line 3, you already declared tool to be script.Parent, don’t need to do it again (line 9)
  • load your animation first before the game starts
  • don’t use wait(), task.wait() is better as it is 60hz (i think), precise to the Heartbeat and doesn’t throttle, meaning it doesn’t lag if the player lags :coefficients:

if there’s still any problems with your script
feel free to ping me :happy1:

1 Like

Hey! Thanks, I’m just wondering how I replace Humanoid with animator.

You put the animator inside the humanoid.
Try playing your animation in a different place on a blank rig and see if it plays.

Humanoid:LoadAnimation Not work
Use

Humanoid.Animator:LoadAnimation()

I dont know if this is wil suite you well, but what works for me all the time when i make scripts like this i do the script.Parent.Activated event in a local script and using a remote event you can get it on a serverscript. Like i said, I dont know if this is wil suite you well but you can try. Thought might sharing.

1 Like

Okay, so I did this;

local leftPunch = script:WaitForChild("LeftPunch")
local rightPunch = script:WaitForChild("RightPunch")
local tool = script.Parent


local debounce = false
local waitTime = 0.4

local activated = nil
local animation = nil
local animation2 = nil

tool.Equipped:Connect(function()
	
	local Character = tool.Parent
	local Humanoid = Character:FindFirstChildWhichIsA("Humanoid")

	animation = Humanoid.Animator:LoadAnimation(leftPunch)
	animation2 = Humanoid.Animator:LoadAnimation(rightPunch)

	activated = tool.Activated:Connect(function()
		if debounce == false then

			debounce = true
			-----------------------
			local rn = math.random(1,2)

			if rn == 1 then
				print("Debug1")
				animation:Play()
			elseif rn == 2 then
				print("Debug2")
				animation2:Play()
			end
			-----------------------
			task.wait(waitTime)
			debounce = false
		end

	end)
end)

tool.Unequipped:Connect(function()
	activated:Disconnect()
end)

Same issue.

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