Problem with Animation:Play()

Hi, I tried to make ability for a tool but the animation won’t play here is the script
I don’t understand why won’t the animation play

------------------Main-----------------
local RaycastHitbox = require(game.ReplicatedStorage.RaycastHitboxV4)
local Hitbox = RaycastHitbox.new(script.Parent.Handle)
local uis = game:GetService("UserInputService")
Hitbox.Visualizer = true
local CurrentHumnanoid
local idle
local CurrentAnimation
local CurrentAnimation2
local CurrentAnimation3
local Spin = script.Spin
local db = true
local click = 0
------------------ShortNames-----------
local tool = script.Parent
local char = tool.Parent
local humanoid = char:FindFirstChild("Humanoid")
local handle = tool:FindFirstChild("Handle")
local T = 1
local Dmg = 19.75
local cd = .7
------------------functions------------

script.Parent.Activated:Connect(function()
	if db then
		db = false

		click += 1
		if click == 1 then
			Hitbox:HitStart(.55)
			if CurrentAnimation then
				CurrentAnimation:Play()
			end
		elseif click == 2 then
			Hitbox:HitStart(.55)
			if CurrentAnimation2 then
				CurrentAnimation2:Play()
				click = 0
			end
		end
		wait(cd)
		db = true
	end
end)

script.Parent.RemoteEvent.OnServerEvent:Connect(function(caller, KeyCode) -------line 46
	if KeyCode == Enum.KeyCode.Q then
		print("dsa")
		if db then
			db = false
			Hitbox:HitStart(2)
			Spin:Play()
		end
	wait(T)
	db = true
end
end)

Hitbox.OnHit:Connect(function(Part, Humanoid)
	if Humanoid and Humanoid ~= script.Parent.Parent.Humanoid then
		Humanoid:TakeDamage(Dmg)
	end
end)

tool.Equipped:Connect(function()
	local Humanoid = script.Parent.Parent:FindFirstChild("Humanoid")
	if Humanoid and Humanoid ~= CurrentHumnanoid then
		CurrentHumnanoid = Humanoid
		idle = script.Parent.Parent.Humanoid:LoadAnimation(script.Idle)
		idle.Priority = Enum.AnimationPriority.Action
		idle.Looped = true
		idle:Play()
		CurrentAnimation = Humanoid.Animator:LoadAnimation(script.Slash)
		CurrentAnimation2 = Humanoid.Animator:LoadAnimation(script.Slash2)
		Spin = Humanoid.Animator:LoadAnimation(script.Spin)
	end
end)

script.Parent.Unequipped:Connect(function()

end)

local:

local RaycastHitbox = require(game.ReplicatedStorage.RaycastHitboxV4)
local Hitbox = RaycastHitbox.new(script.Parent.Handle)
local uis = game:GetService("UserInputService")
local db = true

uis.InputBegan:Connect(function(input, gameProcessedEvent)
	if gameProcessedEvent == false then
		script.Parent.RemoteEvent:FireServer(input.KeyCode)
	end
end)

animation location:
https://gyazo.com/450809bd03bcc5d5678276fc14c569a2

1 Like

Your way of loading animations is superseded by Humanoid.Animator:LoadAnimation(animID). Try changing it to my recommended method and update me ur results.

didn’t work gave me Humanoid is not valid member of backpack

I would help if there was an error involved and that you provide it here.

sure, (ig)
https://gyazo.com/104478c819afa485f1889bf38c809722

You have to get the humanoid from the players character, not the backpack, it works like this:

local player = game:GetService("Players")
local character = player.Character or player.CharacterAdded:Wait()

character:WaitForChild("Humanoid"):LoadAnimation(animation)

2 Likes

Character is not valid member of players “players”
sorry for late response I was gone

1 Like

Can I see what your player variable is declared as?

this?

------------------ShortNames-----------
local tool = script.Parent
local player = game:GetService("Players")
local character = player.Character or player.CharacterAdded:Wait()
local handle = tool:FindFirstChild("Handle")
local T = 1
local Dmg = 19.75
local cd = .7
script.Parent.RemoteEvent.OnServerEvent:Connect(function(caller, KeyCode) -------line 46
	if KeyCode == Enum.KeyCode.Q then
		print("dsa")
		if db then
			db = false
			Hitbox:HitStart(2)
			character:WaitForChild("Humanoid"):LoadAnimation(9304484527)
		end
	wait(T)
	db = true
end
end)

Is the script you declared it in a local script?

wait local? I thought I was supposed to put it in server

Well, the player variables value is the service Players and not the actual player object. Don’t change the script type just yet.

So here’s a fix to your problem:

------------------ShortNames-----------
local character

local tool = script.Parent
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
character = player.Character or player.CharacterAdded:Wait()
end)
local handle = tool:FindFirstChild("Handle")
local T = 1
local Dmg = 19.75
local cd = .7

https://gyazo.com/cbee11090f2cf2142d25e7390c07be94 now i am getting this error

Can you show me line 56 of that script?

script.Parent.RemoteEvent.OnServerEvent:Connect(function(caller, KeyCode) -------line 46
	if KeyCode == Enum.KeyCode.Q then
		print("dsa")
		if db then
			db = false
			Hitbox:HitStart(2)
			character:WaitForChild("Humanoid"):LoadAnimation(9304484527)
		end
	wait(T)
	db = true
end
end)

line 56 is

character:WaitForChild("Humanoid"):LoadAnimation(9304484527)

You can play animations on the client directly.

and how exactly?
(character limit)