Help with animation reversing on finish

I have an animation that plays when a player presses a button. Said animation immediatly reverses whenever the animation is completed. I would like to make it so once the animation has reached the end, instead of reversing, it stops, and if the player presses the button again, it then reverses the animation. I have tried doing this with a bool value in the player to tell when is when and blah blah blah, nothing is working.
heres base code if you need it

local id = "rbxassetid://74538948904973"
	local animator = character.Humanoid:FindFirstChildOfClass("Animator")
	local animation = Instance.new("Animation")
	animation.AnimationId = id
	local animationTrack = animator:LoadAnimation(animation)
	animationTrack:Play()

try this:

local id = "rbxassetid://74538948904973"
	local animator = character.Humanoid:FindFirstChildOfClass("Animator")
	local animation = Instance.new("Animation")
	animation.AnimationId = id
	local animationTrack = animator:LoadAnimation(animation)
	animationTrack.Ended:Connect(function()
		animationTrack:Stop()
	end)
	animationTrack:Play()