I am trying so hard to make a Transformers style game, but I had a problem at animations. Basically when a player hits the “T” key, like Shift-To-Sprint, it will play some animations, make the player speed and jump power to 0, change the animation of the character (walk, run, jump, etc.) then reset the player speed and jump power.
My problem is that the animation of the character is not changing at all.
I tried cahnging the AnimationId for animations, nothing. Tried replacing the Animate local script with another, fail. What can I do to fix this problem?
My Animate Local Script
local UIS = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Character = Player.Character
UIS.InputBegan:connect(function(input)
if input.KeyCode == Enum.KeyCode.T then
--effect
Character.Humanoid.WalkSpeed = 0
Character.Humanoid.JumpPower = 0
--Animation event
local animateScript = script.Parent.Animate
animateScript.walk.WalkAnim.AnimationId = "rbxassetid://5550098749"
animateScript.run.RunAnim.AnimationId = 'rbxassetid://5550098749'
animateScript.idle.Animation1.AnimationId = "rbxassetid://5550101223"
animateScript.idle.Animation2.AnimationId = "rbxassetid://5550101223"
--Transformation
local Anim = Instance.new("Animation")
Anim.AnimationId = "rbxassetid://5550143762" -- Put here your animation id!
PlayAnim = Character.Humanoid:LoadAnimation(Anim)
PlayAnim:Play()
wait(4.2)
Character.Humanoid.WalkSpeed = 30
Character.Humanoid.JumpPower = 0
end
end)
UIS.InputEnded:connect(function(input)
if input.KeyCode == Enum.KeyCode.T then
--effect
Character.Humanoid.WalkSpeed = 0
Character.Humanoid.JumpPower = 0
--Animation event
while not Player.Character do wait() end
local animateScript = Character.Animate
animateScript.walk.WalkAnim.AnimationId = "rbxassetid://5550089689"
animateScript.run.RunAnim.AnimationId = 'rbxassetid://5550089689'
animateScript.idle.Animation1.AnimationId = "rbxassetid://5550107647"
animateScript.idle.Animation2.AnimationId = "rbxassetid://5550107647"
--Transformation
local Anim = Instance.new("Animation")
Anim.AnimationId = "rbxassetid://5550143762" -- Put here your animation id!
PlayAnim = Character.Humanoid:LoadAnimation(Anim)
PlayAnim:Play()
wait(4.2)
Character.Humanoid.WalkSpeed = 16
Character.Humanoid.JumpPower = 50
end
end)
Please note that the Animate script is overwritten with my animations and the character rig and anims are R6. Sorry for repeating 'Animation".
I do not know how the Animate script runs, but I can assume it goes through the animation objects and assigns variables to the return value of the :LoadAnimation() method. If I am following you correctly, you have the default Animate script, you load the transform animation and play it, and lastly, you change the values of the animation objects in the Animate script- where the animations don’t update. If this is the case, it makes sense as to why the animations aren’t updating.
--Let's imagine we have an Animation object, assigned to the ID of "123"
local AnimationObject = Instance.new("Animation")
AnimationObject.AnimationId = 123
--The Animate script likely LOADS the animation into the humanoid
local MyAnim = Humanoid:LoadAnimation(AnimationObject)
--MyAnim is now the loaded-in animation
--We then change the Animation object
AnimationObject.AnimationId = 456
--AnimationObject has successfully been changed
--Let's now play MyAnim
MyAnim:Play()
--It runs animation '123', because THAT'S the animation that was loaded-in and assigned to MyAnim
I am not in studio to test this, but this is my theory as to what your issue is being caused by. If this is indeed the issue, you are likely going to have to create your own script to handle animations. What I would personally do is this:
Create an animation script which handles animations for movement, idle, jump, fall, etc.
Create two folders in the script, one that stores normal human animations, the other to store the post-transform animations.
When the Transform animation is played, reassign all of the animation variables to the :LoadAnimation() of the animations in the ‘transform animation’ folder
When Transform is played once again, reassign the variables back to the animations in the ‘original animation’ folder