Help with animation

Hi!
I’ve made another post about this but it was becoming a thread and I was having different errors so I’m making a new post.

I’m getting the error Workspace.Scimitar.Script:53: attempt to index nil with 'Animator'

Here’s the code used. (shortened version)

local Humanoid = tool.Parent:FindFirstChild("Humanoid")
local Animator = Humanoid.Animator

local Sword_Walk_Animation = Instance.new("Animation")
Sword_Walk_Animation.AnimationId = "rbxassetid://9404399317"
local AnimationTrackWalk = Humanoid.Animator:LoadAnimation(Sword_Walk_Animation)

local Sword_Idle_Animation = Instance.new("Animation")
Sword_Idle_Animation.AnimationId = "rbxassetid://9404394687"
local AnimationTrackIdle = Humanoid.Animator:LoadAnimation(Sword_Idle_Animation)

local function EquippedAnimations()
	Humanoid.Running:Connect(function(speed)
		if speed > 0 then
			AnimationTrackWalk:Play()
			AnimationTrackIdle:Stop()
		else
			AnimationTrackWalk:Stop()
			AnimationTrackIdle:Play()
		end
	end)
end


lines 52-73 ^

Any help would be appreciated as I need to get this demo done within today.

Any chance you can send the full/more of the source?

Humanoid isn’t found basically. line 52

Try this

local Humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid") 
local Animator = Humanoid.Animator

local Sword_Walk_Animation = Instance.new("Animation")
Sword_Walk_Animation.AnimationId = "rbxassetid://9404399317"
local AnimationTrackWalk = Humanoid.Animator:LoadAnimation(Sword_Walk_Animation)

local Sword_Idle_Animation = Instance.new("Animation")
Sword_Idle_Animation.AnimationId = "rbxassetid://9404394687"
local AnimationTrackIdle = Humanoid.Animator:LoadAnimation(Sword_Idle_Animation)

local function EquippedAnimations()
	Humanoid.Running:Connect(function(speed)
		if speed > 0 then
			AnimationTrackWalk:Play()
			AnimationTrackIdle:Stop()
		else
			AnimationTrackWalk:Stop()
			AnimationTrackIdle:Play()
		end
	end)
end 

Try this instead:

local Animator = Humanoid:FindFirstChildOfClass("Animator")
Workspace.Scimitar.Script:53: attempt to index nil with 'FindFirstChildOfClass'

Is this local script or server?

Nevermind i assume its server script since its sitting on your workspace?

1 Like

server script.

So this is a tool that someone picks up and then is no longer in the workspace but their backpack?

Can i see how u’ve defined the tool for this line:

local tool = script.Parent

it’s picked up in workspace.

So then i believe it should be:

Had to do some adjusting as it resulted in Character being defined as “Workspace”

local Character = game.Players
local Humanoid = Character:FindFirstChild("Humanoid")
local Animator = Humanoid.Animator

Workspace.Scimitar.Script:54: attempt to index nil with ‘Animator’

If you can’t help me that’s okay, thank you for at least trying :smile:

1 Like