Toggle animations on keybinds

So I would like to make a animation, it’s for a military group. So like that they stand in attention. Although I have no clue how to make that. Anyone got an idea?

--LocalScript
local Players = game:GetService("Players");
local UserInputService = game:GetService("UserInputService");

local plr = Players.LocalPlayer;
local char = plr.Character or plr.CharacterAdded:Wait();
local hum = char:WaitForChild("Humanoid");

local anim = Instance.new("Animation");
anim.AnimationId = "rbxassetid://id_here"; --Put the animation id here
local track = hum:LoadAnimation(anim);

function playAnim()
	if not track.IsPlaying then
		track:Play(); --Play the animation if not playing
	else
		track:Stop(); --Stop it if playing
	end
end

function onInput(key, gpe)
	--You can change the keybind here if you want.
	if not gpe and key.KeyCode == Enum.KeyCode.E then
		playAnim();
	end
end
UserInputService.InputBegan:Connect(onInput);
1 Like

How do I like make it toggle. I want them to press it once, they stay in that position, And they once they press it again, they undo the animation

That’s what the script should do.