Not quite, Heres a edited version so you can see
The only issue with your one was that it would only stop the run animation constantly
Not quite, Heres a edited version so you can see
The only issue with your one was that it would only stop the run animation constantly
Ahhhhhhhhhhhhh, I see, I think. Thanks, I will see if it works!
On a side note when using for loops its key to remember the two elements
– Commonly used method
for Index , Table in pairs do
end
— My prefered method
for Index = 1, #Table
end
Oh wait, do you literally write Index or do you replace both “Index” with something else? Sorry, I am not the best at scripting
Okay so Index is like a variable that only exists in the loop
For each object in an array it will run, all index does is tell you which number object
for example
Table = {"A","B","C"}
for i = 1,#Table do
print(i)
print(Table[i])
end
would result in
1 - A
2 - B
3 - C
However when you set it to only
it would do the same thing despite having different values in an array.
Oh ok I get it. Thanks! I definitely need to use that.
The name of the variable is misleading. The code will stop each animation track.
Maybe if I wrote it like this,
playingTracks = humanoid:GetPlayingAnimationTracks()
for _, playingTrack in pairs(playingTracks) do
playingTrack:Stop(0)
end
it would be more obvious.
Yeah I am still stuck, the CharacterAppearance loads before I can set the values, or when I have it wait till afterwards it just does nothing…
I tried that as well, the whole thing still did not work
When changing the animations, the animate script only updates the existing animations once a child/descendant has been modified or added. Changing the animation IDs for each animation won’t trigger this, so it won’t reload the animations that you select.
Just clone the existing animation objects, delete the old ones, and change the IDs like you have done already and it should work properly. The loop has nothing to do with it - all it does is tell you which tracks are playing. You don’t even need to stop those tracks, you can forego the loop entirely, since the animate script will reload all your animations for you.
Ok yes but the function only runs when it is connected by CharacterAppearanceLoaded, which runs only once at the start of the game, before it has time to set the values. And I need some line of code to run that again like LoadCharacterApearance(), but it is depreciated.
You can set it at any time in the game using the method I mentioned. You don’t need to rely on character loading or otherwise; that said, you need to make sure the animate script and all the descendants are loaded in. You can throw in a few WaitForChild
’s to do that.
So I did what you said using this method?
local firstanimation = animateScript.run.RunAnim.AnimationId
local firstanimationClone = firstanimation:Clone()
animateScript.run.RunAnim.AnimationId:Destory()
firstanimationClone = "rbxassetid://616163682"
And I am getting
ServerScriptService.ChangeAnimationScript:34: attempt to call a nil value
Is this a typo in the code sample or is this a typo in your code that is giving you the error? (it would be helpful to provide line numbers or indicate which line is the one you are getting the error for)
Sorry, yes typo, I fixed it and it still didn’t work.
13 local firstanimation = animateScript.run.RunAnim
14 local firstanimationClone = firstanimation:Clone()
15 animateScript.run.RunAnim:Destroy()
16 firstanimationClone.AnimationId = "rbxassetid://616010382" -- Run
17 local secondanimation = animateScript.walk.RunAnim
18 local secondanimationClone = secondanimation:Clone()
19 animateScript.walk.RunAnim:Destroy()
20 secondanimationClone.AnimationId = "rbxassetid://616013216"
And right now I am getting
15:37:41.266 RunAnim is not a valid member of StringValue "Workspace.MRKYLO20.Animate.run" - Server - ChangeAnimationScript:13
15:37:41.267 Stack Begin - Studio
15:37:41.267 Script 'ServerScriptService.ChangeAnimationScript', Line 13 - function onCharacterAdded - Studio - ChangeAnimationScript:13
15:37:41.267 Stack End
My apologies by the way, I am not the best at scripting and I am trying to learn this… So thanks for spending the time to help me.
That issue looks like when the character is added, not all of the descendants of the script have loaded yet. Instead of this,
13 local firstanimation = animateScript.run.RunAnim
You may have to call WaitForChild("run"):WaitForChild("RunAnim")
instead. This will wait until everything is loaded in the character. You would need to do this for all the animations - secondanimation, thirdanimation, etc. that you want to change.
13 local firstanimation = animateScript.run:WaitForChild("RunAnim")
or
13 local firstanimation = animateScript:WaitForChild("run"):WaitForChild("RunAnim")
You could optionally put a wait(2)
if you want a quick fix, but it doesn’t guarantee that everything has loaded. It just gives extra time to wait, hoping that everything in the character has loaded 2 seconds later.
13 wait(2)
14 local firstanimation = animateScript.run.RunAnim
Alrighty, yes! your script accomplished my first goal, which was to change the script the first time, now my main intention is to be able to change it multiple times possibly in my shop. Let me show you my whole animation changer script
local aksdfkjf = false
local Players = game:GetService("Players")
local function onCharacterAdded(character)
local humanoid = character:WaitForChild("Humanoid")
print("haha")
for _, playingTracks in pairs(humanoid:GetPlayingAnimationTracks()) do
playingTracks:Stop(0)
end
local animateScript = character:WaitForChild("Animate")
wait(1)
local firstAnimation = animateScript:WaitForChild("run"):WaitForChild("RunAnim")
local firstAnimationClone = firstAnimation:Clone()
animateScript.run.RunAnim:Destroy()
firstAnimationClone.AnimationId = "rbxassetid://616010382"
local secondAnimation = animateScript.walk.RunAnim
local secondAnimationClone = secondAnimation:Clone()
animateScript.walk.RunAnim:Destroy()
secondAnimationClone.AnimationId = "rbxassetid://616013216"
local thirdAnimation = animateScript.jump.JumpAnim
local thirdAnimationClone = thirdAnimation:Clone()
animateScript.jump.JumpAnim:Destroy()
thirdAnimationClone.AnimationId = "rbxassetid://616008936"
local fourthAnimation = animateScript.idle.Animation1
local fourthAnimationClone = fourthAnimation:Clone()
animateScript.idle.Animation1:Destroy()
fourthAnimationClone.AnimationId = "rbxassetid://616006778"
local fifthAnimation = animateScript.idle.Animation2
local fifthAnimationClone = fifthAnimation:Clone()
animateScript.idle.Animation2:Destroy()
fifthAnimationClone.AnimationId = "rbxassetid://616008087"
local sixthAnimation = animateScript.fall.FallAnim
local sixthAnimationClone = sixthAnimation:Clone()
animateScript.fall.FallAnim:Destroy()
sixthAnimationClone.AnimationId = "rbxassetid://616005863"
local seventhAnimation = animateScript.swim.Swim
local seventhAnimationClone = seventhAnimation:Clone()
animateScript.swim.Swim:Destroy()
seventhAnimationClone.AnimationId = "rbxassetid://616011509"
local eighthAnimation = animateScript.swimidle.SwimIdle
local eighthAnimationClone = eighthAnimation:Clone()
animateScript.swimidle.SwimIdle:Destroy()
eighthAnimationClone.AnimationId = "rbxassetid://616012453"
local ninthAnimation = animateScript.climb.ClimbAnim
local ninthAnimationClone = ninthAnimation:Clone()
animateScript.climb.ClimbAnim:Destroy()
ninthAnimationClone.AnimationId = "rbxassetid://616003713"
end
local function onCharacterAddedOther(character)
local humanoid = character:WaitForChild("Humanoid")
print("haha")
for _, playingTracks in pairs(humanoid:GetPlayingAnimationTracks()) do
playingTracks:Stop(0)
end
local animateScript = character:WaitForChild("Animate")
wait(1)
local firstAnimation = animateScript:WaitForChild("run"):WaitForChild("RunAnim")
local firstAnimationClone = firstAnimation:Clone()
animateScript.run.RunAnim:Destroy()
firstAnimationClone.AnimationId = "rbxassetid://750783738"
local secondAnimation = animateScript.walk.RunAnim
local secondAnimationClone = secondAnimation:Clone()
animateScript.walk.RunAnim:Destroy()
secondAnimationClone.AnimationId = "rbxassetid://750785693"
local thirdAnimation = animateScript.jump.JumpAnim
local thirdAnimationClone = thirdAnimation:Clone()
animateScript.jump.JumpAnim:Destroy()
thirdAnimationClone.AnimationId = "rbxassetid://750782230"
local fourthAnimation = animateScript.idle.Animation1
local fourthAnimationClone = fourthAnimation:Clone()
animateScript.idle.Animation1:Destroy()
fourthAnimationClone.AnimationId = "rbxassetid://750781874"
local fifthAnimation = animateScript.idle.Animation2
local fifthAnimationClone = fifthAnimation:Clone()
animateScript.idle.Animation2:Destroy()
fifthAnimationClone.AnimationId = "rbxassetid://750782770"
local sixthAnimation = animateScript.fall.FallAnim
local sixthAnimationClone = sixthAnimation:Clone()
animateScript.fall.FallAnim:Destroy()
sixthAnimationClone.AnimationId = "rbxassetid://750780242"
local seventhAnimation = animateScript.swim.Swim
local seventhAnimationClone = seventhAnimation:Clone()
animateScript.swim.Swim:Destroy()
seventhAnimationClone.AnimationId = "rbxassetid://750784579"
local eighthAnimation = animateScript.swimidle.SwimIdle
local eighthAnimationClone = eighthAnimation:Clone()
animateScript.swimidle.SwimIdle:Destroy()
eighthAnimationClone.AnimationId = "rbxassetid://750785176"
local ninthAnimation = animateScript.climb.ClimbAnim
local ninthAnimationClone = ninthAnimation:Clone()
animateScript.climb.ClimbAnim:Destroy()
ninthAnimationClone.AnimationId = "rbxassetid://750779899"
end
local function whichAnim(character)
local player = game.Players:GetPlayerFromCharacter(character)
if not player:FindFirstChild("PlayerAnim") then
aksdfkjf = true
end
if player:WaitForChild('PlayerAnim').Value == "DefaultAnim" then
print("You have the DefaultAnimation")
player.CharacterAppearanceLoaded:Connect(onCharacterAdded)
end
if player:WaitForChild('PlayerAnim').Value == "OtherAnim" then
print("You have the OtherAnimation")
player.CharacterAppearanceLoaded:Connect(onCharacterAddedOther)
end
wait(1)
if aksdfkjf == true then
player:LoadCharacter()
aksdfkjf = false
end
end
local function onPlayerAdded(player)
player.CharacterAdded:Connect(whichAnim)
end
Players.PlayerAdded:Connect(onPlayerAdded)
This is a clip of my new issue, the DefaultAnim is what my character starts with, when I use the Proximity Prompt (my substitution for my shop until I get this whole terrible and funky issue fixed), it changes it to the OtherAnim, which is a pirate animation, but it won’t change as you can see.
robloxapp-20201215-1838488.wmv (4.6 MB)
(sorry I am unsure how to put a video on the forum from studio without it coming up as a download)
I am getting this error normally too, but it isn’t affecting the game…
18:43:42.219 Infinite yield possible on 'Workspace.MRKYLO20.Animate.run:WaitForChild("RunAnim")' - Studio
18:43:42.220 Stack Begin - Studio
18:43:42.221 Script 'ServerScriptService.ChangeAnimationScript', Line 13 - function onCharacterAdded - Studio - ChangeAnimationScript:13
18:43:42.222 Stack End - Studio
I would think that this would halt the whole thing, but it doesn’t, it may have nothing to do with the main problem, but I don’t know?
No that is one of the main issues. It appears as though the run animation doesn’t exist. At all. Which is weird.
I have a fix though. I implemented this about a month ago and it worked well, but now looking back I noticed I did something different than what I described to you in my earlier posts.
First thing: I have a folder in server storage that holds the default animations when I want to switch back to default. Notice that I keep everything that the Animate script would have.
You can grab these by pressing play in studio and going to your character model (It will have the animations you have on your avatar; if you unequip the ninja animation pack beforehand you will get the default ones).
Make sure you grab everything under the animate script. You don’t need the animate script itself. The image above is cropped since I can’t fit the entire list on my screen, but you get the idea I hope.
The second part is to select the animations that you need/that you are going to change. For me, all I needed to change were these (again, another folder under server storage):
(Keep the non-animation stuff too like the remote function and the scale dampening constant)
In your case, this would be your pirate animation. You would change the animation IDs for the animation objects in each one, but ahead of time rather than in the script. You will see why in a second.
Now the scripting part. It’s actually very simple, since you’ve pre-selected all the animations. We will use the behaviour of the animation script that auto-updates the animations, but instead we will remove everything under the animation script, rather than looking for something specific, and then replace it with all the new stuff.
(warning: I didn’t test this code so check for typos)
local DefaultAnimations = game:GetService("ServerStorage").Default
local PirateAnimations = game:GetService("ServerStorage").Pirate
local function onCharacterAdded(character)
local humanoid = character:WaitForChild("Humanoid")
local animateScript = character:WaitForChild("Animate")
wait(1)
for _, stuff in pairs(animateScript:GetChildren()) do
stuff:Destroy()
end
for _, stuff in pairs(DefaultAnimations:GetChildren()) do
local newStuff = stuff:Clone()
newStuff.Parent = animateScript
end
end
And you would do the same thing for your pirate animation. Hope this helps
HALLEUJAH!!! IT WORKS!!! Thanks so much!! And I am sorry it took forever, I am such a dummy. Thanks again!