My script is within a local script, I have done some testing and I have found out that the If Statement is running when the animation is in the state to be held down, and not running when shift is released which is just what I want. Here is a link to the animation I am using, I made it myself: Animation Link. This script is a Local Script being run inside a tool, its parent is the tool. Here is my script for it:

UserInputService = game:GetService("UserInputService")
player = game:GetService("Players").LocalPlayer
character = player.Character
ReleasedShift = true
if not character or not character.Parent then
    character = player.CharacterAdded:Wait()
end
humanoid = character:WaitForChild("Humanoid")
sprintAnimation = Instance.new("Animation")
sprintAnimation.AnimationId = "rbxassetid://5260675637"
sprintAnimation = humanoid:LoadAnimation(sprintAnimation)
Equipped = false
script.Parent.Equipped:Connect(function()
    Equipped = true
end)
script.Parent.Unequipped:Connect(function()
    Equipped = false
end)
UserInputService.InputBegan:Connect(function(key)
    if key.KeyCode == Enum.KeyCode.LeftShift then
		if Equipped then	
			ReleasedShift = false        
			sprintAnimation:Play()
			wait(0.3)
			if ReleasedShift == false then
                sprintAnimation:AdjustSpeed(0)
            end
        end
    end
end)
UserInputService.InputEnded:Connect(function(key)
    if key.KeyCode == Enum.KeyCode.LeftShift then
	    if Equipped then
            ReleasedShift = true
            sprintAnimation:AdjustSpeed(1)
        end
    end 
end)

Currently the animation is run but does not stop when finished. My goal is to adjust the speed to 0 when the animation is about to go back to the original state, and set the speed to 1 to continue the animation returning to its original state. Please comment if you have any questions and I will be sure to reply to them ASAP.

3 comments

1

You can use Animation:Stop() function to stop the animation instead

0

Will I be able to Continue the animation after? And will the animation stay in the same state???

0

That did not work could you please give me a code sample on how to use the stop animation while the Variable ReleasedShift == false?