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.