Animatin not playing

  1. What do you want to achieve?
    I am trying to make a gladius play a swinging animation when I click with it.

  2. What is the issue?
    The animation won’t play.

Here is my code:

local Humanoid = script.Parent.Character.Humanoid
local Animation = Humanoid:LoadAnimation(script:WaitForChild("Animation"))
local debounce = false

script.Parent.Parent.Activated:Connect(function()
	if not debounce then
		debounce = true
		Animation:Play()
		wait(0.5)
		Animation:Stop()
		debounce = false
		
		script.Parent.Touched:Connect(function(hit)
			if hit.Parent:FindFirstChild("Humanoid") then
			Humanoid.Health = Humanoid.Health - 15
			end
		end)
	end
end)

The script is a server script inside of the tool’s Handle and the animation is the child of the script.

2 Likes

In the first line try referencing this instead: script.Parent.Parent.Parent:WaitFotChild(“Humanoid”)

Didn’t work. There are also no errors.

Is the problem only with the animation? The tool works but the anim’s not playing?

If so then make sure the animation is published by the creator of the game, for example if its a group then it should be published by the group.

1 Like

Can you do some prints throughout the script just to check where it’s not working?

It’s not working at the animation. Everything else works just fine.

Do the thing I told you to do. (if you havent done it)

I am using the Slash anim that you start with. (Yeah I’m lazy)

What’s the animation priority? Is it something other than core?

The character may have not loaded yet, same with the humanoid and disconnect the event after the animation has ended so you can’t kill others while your not clicking.

If your game is created by a group can the animation is created by you then upload the animation onto the group.

And put your Animation priority to Action.

local Player = script.Parent
local Character = Player.Character or Player.CharacterAdded:Wait()

local Humanoid = Character:WaitForChild("Humanoid")
local Animation = Humanoid:LoadAnimation(script:WaitForChild("Animation"))

local debounce = false

script.Parent.Parent.Activated:Connect(function()
	if not debounce then
        debounce = true
        local connection = script.Parent.Touched:Connect(function(hit)
			if hit.Parent:FindFirstChild("Humanoid") then
			    Humanoid.Health = Humanoid.Health - 15
			end
		end)

		Animation:Play()
		Animation.Stopped:Wait()
        connection:Disconnect()
		debounce = false
	end
end)

Didn’t work.

I have no Idea. The animation is made by Roblox so I assume it should be correct. And also why does it need to be core? Couldn’t it be Action?

Apologies, my intent was it to be that it should be something other than core, not that it needs to be core.

Try this and make sure your character Rig type match the Animation because the Roblox Slash Animation is R6

local Humanoid = script.Parent.Parent.Parent:FindFirstChildWhichIsA("Humanoid")
local debounce = false
--
script.Parent.Parent.Activated:Connect(function()
	local Humanoid = script.Parent.Parent.Parent:FindFirstChildWhichIsA("Humanoid")
	local Animation = Humanoid:LoadAnimation(script:FindFirstChildWhichIsA("Animation"))
	if not debounce then
		debounce = true
		Animation:Play()
		wait(0.5)
		Animation:Stop()
		debounce = false
--	
		script.Parent.Touched:Connect(function(hit)
			local HitHumanoid = hit.Parent:FindFirstChild("Humanoid")
			if hit.Parent.Name ~= Humanoid.Parent.Name and HitHumanoid then
				HitHumanoid:TakeDamage(15)
			end
		end)
	end
end)

Oh, I didn’t know that. So I made my own anim for R15 and it still doesn’t work. (My avatar is R15)

That obviously wouldn’t work because you have a server script inside the tool, server can’t read client’s inputs, so instead make that script a LocalScript, and avoid loading the animation to the Humanoid, it’s highly unrecommended, just load it to the animator.

Oh, ok. How would I call the animator though?

The Animator instance is parented to the Humanoid instance on each player character, so it’s just local animator = Humanoid.Animator and then load it the same way you are doing for humanoid rn.

Here is the new code:

local Humanoid = game.Players.LocalPlayer.Character.Humanoid
local Animator = Humanoid.Animator
local Animation = Animator:LoadAnimation(script:WaitForChild("Animation"))
local debounce = false

script.Parent.Activated:Connect(function()
	if not debounce then
		debounce = true
		Animation:Play()
		wait(0.5)
		Animation:Stop()
		debounce = false

		script.Parent.Touched:Connect(function(hit)
			if hit.Parent:FindFirstChild("Humanoid") then
				Humanoid.Health = Humanoid.Health - 15
			end
		end)
	end
end)

It gives me this error:
13:29:31.805 Players.MRBOGO_YT.Backpack.Gladius.SwordScript:1: attempt to index nil with 'Humanoid' - Client - SwordScript:1

The code is now a local script.

You first need to change the script from a ServerScript to a LocalScript because ServerScripts cant read client’s inputs, your next problem is that you aren’t waiting for those instances to show up, aka the Animator doesn’t exist yet, so you’ll want to WaitForChild() there.

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Animator = Humanoid:WaitForChild("Animator")
local Animation = Animator:LoadAnimation(script:WaitForChild("Animation"))
1 Like