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

Why does this keep saying I'm trying to index a nil value when I try to change the animation Id?

Asked by
Kami_Yo 72
5 years ago

So I am trying to change the default running animation and for some reason my code doesn't work

game.Players.PlayerAdded:Connect(function(player)
    playerCharacter = player.Character

    ourPlayer = player

    for i, v in pairs(playerCharacter.Humanoid:GetPlayingAnimationTracks()) do
        v:Stop(0)
    end

    local AnimateScript = playerCharacter:WaitForChild("Animate")
    for i, animation in pairs(AnimateScript:GetChildren()) do
        print("ANIMATION: ", animation.Name)
    end

    AnimateScript.run.Value = "Run"
    AnimateScript.run:FindFirstChild("RunAmin").AnimationId = "rbxassetid://<id>"

The value of run is changed but for some reason the last line of code here keeps giving me a "attempt to index a nil value". I honestly don't get why this is doesn't work, it seems so simple. All I want is to change the animation id. I know I could make a new Animation localscript but I really want this to work cause it would make things so much easier.

1 answer

Log in to vote
0
Answered by
Kami_Yo 72
5 years ago

I got it to work, but I honestly feel like it is so unnecessary but it works:

I deleted the stringvalue and the animation in it and remade it with my own animation id.

AnimateScript:WaitForChild("run"):Destroy()

local newRun = Instance.new("StringValue")
newRun.Name = "run"
newRun.Value = "run"
newRun.Parent = AnimateScript

local newAnimation = Instance.new("Animation")
newAnimation.AnimationId = "rbxassetid://<id>"
newAnimation.Name = "RunAnim"
newAnimation.Parent = newRun

And now the player runs with the animation I gave it.

0
youre old script was findfirstchild("RunAmin") im going to geuss you made a spelling error while searching for the animation. 129Steve129 7 — 5y
Ad

Answer this question