I'm trying to make an animation that brings your arms up so you hold a gun. Now I have made an animation that goes from standard position and brings the arms up to my wanted position. But when the animation is over, the arms just go back to normal position.
Is there any way I can keep the last position / keyframe of the arms so the player keeps holding that position?
This is the script I used to play the animation, I used the Animation Editor.
local Player = game.Players.LocalPlayer local Mouse = Player:GetMouse() local player = game.Players.LocalPlayer.Character -- Import animation local animation1 = Instance.new("Animation") animation1.AnimationId = "http://www.roblox.com/Asset?ID=1404306400" -- Local variables local animTrack = nil local function PlayAnim(Animation) animTrack = player.Humanoid:LoadAnimation(Animation) -- Load animation into Humanoid animTrack:Play() -- Start the animation end Mouse.Button2Down:connect(function() print("Player Clicked!") PlayAnim(animation1) end)
Hello
I'll post the script i used and i'll explain what i did.
function onEquipped() print('RunAnim') local Animation = Instance.new("Animation") Animation.AnimationId = "rbxassetid://2097348365" local Track = Humanoid:LoadAnimation(Animation) Track:Play() Track.KeyframeReached:connect(function(keyframeName) if keyframeName == "Pause" then Track:AdjustSpeed(0) end end) end)
I made this function to run the code when the gun is equipped. I used the print to check if the code works.
local Animation = Instance.new("Animation")
this creates an animation.
Animation.AnimationId = "rbxassetid://2097348365"
This will set the animation Id so basically the animation you made.
local Track = Humanoid:LoadAnimation(Animation)
This will define the whole animation so you can easily call the animation because it is stored in Track.
Track:Play() will run the animation. So basically you already know all of that. But to make the player stay in that position you have to pause the animation. There might be several ways but i only know this one.
~~~~~~~~~~~~~~~~~
Track.KeyframeReached:connect(function(keyframeName) if keyframeName == "Pause" then Track:AdjustSpeed(0) end end) ~~~~~~~~~~~~~~~~~ The first line: KeyframeReached will run when a keyframe is reached.(You know what keyframes are right?) We make a function and give it the "keyframeName" parameter. then we make an if statement to check if the keyframe is the one we want the animation to stop at. you can name the keyframe anything you want. But i used "Pause" because its easier to understand when debugging is neccesary. when we finish with those lines. we have to actually pause the animation. So we use Track:AdjustSpeed(0) the (0) here will adjust the speed and set it to 0 making the animation pause.
Great! But when you move now. The animation will stop. This is because you have to change the priority. Core (lowest priority) --Basically whatever you do will stop the animation Idle --This will surpress the Core priority. Any animation that has core priority will stop. Movement --This surpresses any animation that has Idle priority Action (highest priority) --I recommend using this for guns etc. Because it surpresses everything.
So change the priority to Action.
Well one more thing. About keyframes.
Don't use the last keyframe as the pause keyframe because since its the last keyframe the animation will stop before the animation could have paused. Use the second last keyframe.
When you will onequip you could make an onequip animation and run it when you unequip the gun. (If you don't know how to do this just reply to me)
And sorry for the late answer. I started scripting 2 months ago.