Sword Not able to play!

Hey, I hate to keep on posting I posted the same topic on scriptinghelpers.org
and nobody could really help me. So heres my problem it tells me on script line 2 that Players.Kykysurvivin.Backpack.Sword.Animation:2: attempt to index nil with ‘Character’
I don’t know if this is something simple but I would Appreciate a little help! Thanks for your time
Here is the code:

local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
 
local SwordAnim = script.Parent:WaitForChild("SwordAnim")
local SwordTrack = Humanoid:LoadAnimation(SwordAnim)
 
script.Parent.Activated:Connect(function()
	SwordTrack:Play(0)
end)
1 Like

no sorry this is the full code I guess I only copied some of it.

local Player = game.Players.LocalPlayer

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

local Humanoid = Character:WaitForChild(“Humanoid”)

local SwordAnim = script.Parent:WaitForChild(“SwordAnim”)

local SwordTrack = Humanoid:LoadAnimation(SwordAnim)

script.Parent.Activated:Connect(function()

SwordTrack:Play(0)

end)

If that’s the case, make sure you’re writing the code inside a local script.

will that work, because the animation and the script are inside a tool

Yup, it should work, animations are automatically replicated

1 Like

Hey so its not working and Im wondering if its because I have a sword server script check this out

local tool = script.Parent
local function onTouch(partOther)
	local humanOther = partOther.parent:FindFirstChild("Humanoid")
	
	if not humanOther then return end
	
	if humanOther.Parent == tool then return end
	
	humanOther:TakeDamage(20)
	
end

tool.Handle.Touched:Connect(onTouch)

The server script seems alright, it’s not interfering. What type of error you’re getting this time? Also could you send me a screenshot of your tool script hierarchy

Yes of course
Sword Tool

What errors are you receiving? Make sure to check that the tool uses the Handle as well in its properties

Well not I am not getting any errors but the Animation still doesnt play.

Please answer the previous question regarding the property of the tool, where you have to check if it uses the handle

Hey, I feel so dumb. Because I just realized that the reason its not working now and there is no errors is because the animation is in r15 and my game runs on r6. So sorry for wasting your time. Thanks for your help!

3 Likes

You should mark this as the solution so that other people can easily find it when they have the same issue :smiley:

Using Humanoid:LoadAnimation() isn’t suggested to be used as it is deprecated. Use Animator:LoadAnimation()

Hey I’m having a different issue now. So when I play the game is says

 Infinite yield possible on 'Players.Kykysurvivin:WaitForChild("Character")'

and I’m confused because even though I’m using R6 I should still have a character in my Player Value

“Character” is not a child of Player, so you don’t need to use WaitForChild

Players.Kykysurvivin.Character

1 Like

is that the full script just Animator or my animation’s name?

Take a look at the example code from the DevHub

I believe using Humanoid instead of Animator won’t make the animation replicate to other clients, as again, is deprecated. But of course you can still use it

Thank you I got that working. But do you have any idea of why when I die the Animation doesn’t play when I click anymore?

I’m not really sure, could you send me a video?

1 Like