local userInputService = game:GetService("UserInputService") local Player = game.Players.LocalPlayer local Character = Player.Character or Player.CharacterAdded local Anim = Instance.new("Animation") --this is for any inputs at all userInputService.InputBegan:Connect(function(input,GameProcessedEvent) if input.KeyCode == Enum.KeyCode.E then local humanoid = Player.Character.Humanoid Anim.AnimationId = "rbxassetid://986231579" local playAnim = humanoid:LoadAnimation(Anim) script.Parent.Handle.Transparency = 0.5 if script.Parent.Handle.Transparency == 0.5 then script.Parent.Sound:Play() playAnim:Play() end end end) --this is for when the e key is pressed down --the gameProcessedEvent is so the game recognizes the event i assume its for making server events with a local script userInputService.InputEnded:Connect(function(input,GameProcessedEvent) if input.KeyCode == Enum.KeyCode.E then local humanoid = Player.Character.Humanoid Anim.AnimationId = "rbxassetid://986231579" local playAnim = humanoid:LoadAnimation(Anim) script.Parent.Handle.Transparency = 1 playAnim:Stop() end end) userInputService.InputEnded:Connect(function(input,GameProcessedEvent) if input.KeyCode == Enum.KeyCode.E then script.Parent.Sound:Stop() end end) --this is for when the e key is let go of
You are trying to make a new animation play when the player releases E instead of stop the currently playing one. To fix this you need to place a variable at the top to store the playing animation and stop it when the player releases the key as so:
local userInputService = game:GetService("UserInputService") local Player = game.Players.LocalPlayer local Character = Player.Character or Player.CharacterAdded local Anim = Instance.new("Animation") local humanoid = Player.Character.Humanoid -- Declare the Humanoid here since its before the InputBegan event local playAnim = humanoid:LoadAnimation(Anim) --Declare the animation here Anim.AnimationId = "rbxassetid://986231579" -- Set the ID here since its before the InputBegan event --this is for any inputs at all userInputService.InputBegan:Connect(function(input,GameProcessedEvent) if input.KeyCode == Enum.KeyCode.E then script.Parent.Handle.Transparency = 0.5 if script.Parent.Handle.Transparency == 0.5 then script.Parent.Sound:Play() playAnim:Play() --Start the animation we stored at the top end end end) --this is for when the e key is pressed down --the gameProcessedEvent is so the game recognizes the event i assume its for making server events with a local script userInputService.InputEnded:Connect(function(input,GameProcessedEvent) if input.KeyCode == Enum.KeyCode.E then script.Parent.Handle.Transparency = 1 playAnim:Stop() --Stop the animation we stored at the top end end) userInputService.InputEnded:Connect(function(input,GameProcessedEvent) if input.KeyCode == Enum.KeyCode.E then script.Parent.Sound:Stop() end end) --this is for when the e key is let go of
place
local playAnim = humanoid:LoadAnimation(Anim)
on the top because your loading a new animation everytime you click E and stop clicking E so its not the same animation that your trying to stop