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.
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.