Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Players.kidsteve923.Backpack.Sword.LocalScript:16: attempt to call a nil value?

Asked by 3 years ago

i wanted to play animation1 first then animation and then again animation1 as i am making a sword

local plr = game.Players.LocalPlayer
local character = plr.Character or plr.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local sound = script.Parent.Handle.OverheadSound
local sound2 = script.Parent.Handle.UnsheathSound

local animations = "rbxassetid://6779827280"
local animation1 = "rbxassetid://6780070275"
local animationplayer = script.Parent.Handle.Animation

local CanAttack = true

script.Parent.Activated:connect(function()
    if animationplayer.AnimationId == animation1 then
        CanAttack = false
        animation1:Play()
        animationplayer.AnimationId = animations
        wait(0.2)
        CanAttack = true
    else
        CanAttack = false
        animations:Play()
        animationplayer.AnimationId = animation1
        wait(0.2)
        CanAttack = true
    end
end)

local idelanim = script.Parent.Handle.asd
local idealanimation = humanoid:LoadAnimation(idelanim)

script.Parent.Equipped:Connect(function()
    idealanimation:Play()
    sound2:Play()
end)

script.Parent.Unequipped:Connect(function()
    idealanimation:Stop()
end)

2 answers

Log in to vote
0
Answered by 3 years ago

Hello, this is how we properly load and play animations.

local player = game.Players.LocalPlayer --gets the player
local character = player.Character or player.CharacterAdded:Wait() --gets its character
local humanoid = character:WaitForChild("Humanoid") --gets the humanoid
local animator = humanoid:WaitForChild("Animator") --gets the animator

local animation = character.Animation --gets the animation object (ofcourse, change it to your animation's address)
local animTrack = animator:LoadAnimation(animation) --loads the animation so we can play it

animTrack:Play() --plays the animation

What you were doing was playing strings instead of AnimationTracks. I hope this makes sense, good luck!

0
This is actually true. The animation ID can not play by itself. Only the animation instance can. Also, only the animator can load animations. If you see humanoid:LoadAnimation, that id deprecated. Finty_james 269 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

I'm not an animations specialist though, I still know you need to make an animation in order to play it.

local animation1In = Instance.new(Animation)
animation1In.AnimationId = animation1
--install this somewhere between the variables and where you call it, yet still on global scope.
--and rewrite animation1 into animation1In in line 16

i moved to python half a year ago if I messed up something terribly sorry!

Answer this question