The animation is not stopping

What do you want to achieve? Keep it simple and clear!
I made a script to load an animation for skill when the key Down but when the key is Key Up the animation is not stopping

-- Script Inside the ServerScript
local Event = script.Parent
local avaibleAnimationIds = {"7268865430", "7268875953", "7268878561"}

Event.OnServerEvent:Connect(function(player,active,mouseaim)
	local Character = player.Character

	local newAnimator = Instance.new("Animation", Character)
	newAnimator.Name = "Hold_Anim"
	newAnimator.AnimationId = "rbxassetid://"..avaibleAnimationIds[1]

	if active == true then
		local ReleaseAnim = Character:WaitForChild("Humanoid"):LoadAnimation(newAnimator) -- Creating the animation loader
		ReleaseAnim:Stop()
		
		Event:FireClient(player)
	else	
		
		local ReleaseAnim = Character:WaitForChild("Humanoid"):LoadAnimation(newAnimator) -- Creating the animation loader
		ReleaseAnim:Play()
		newAnimator:Destroy()
	end
end)
-- Script inside the Local Script
wait(1)
local UIS = game:GetService("UserInputService")


local Event= script.Event

local Player = game.Players.LocalPlayer
local character = Player.Character
if not character or not character.Parent then
	character = Player.CharacterAdded:wait()
end

local Root = character:WaitForChild("HumanoidRootPart")

local mouse = Player:GetMouse()

local active = false
local debounce = false

local cooldown = 2


UIS.InputBegan:Connect(function(Input,isTyping)
	if isTyping then
		return
	elseif Input.KeyCode == Enum.KeyCode.Z then
		if debounce == false and active == false then
			debounce = true
			Event:FireServer(active,mouse)
		end
	end
end)

UIS.InputEnded:Connect(function(Input,isTyping)
	if isTyping then
		return
	elseif Input.KeyCode == Enum.KeyCode.Z then
		if debounce == true and active == false then
			active = true
			Root.CFrame = CFrame.new(Root.Position, Root.Position + mouse.Hit.LookVector)
			Event:FireServer(active,mouse)
		end
	end
end)

Event.OnClientEvent:Connect(function()
	wait(cooldown)
	debounce = false
	active = false
end)

Try this:

local Event = script.Parent
local avaibleAnimationIds = {"7268865430", "7268875953", "7268878561"}

Event.OnServerEvent:Connect(function(player,active,mouseaim)
	local Character = player.Character

	local newAnimator = Instance.new("Animation", Character)
	newAnimator.Name = "Hold_Anim"
	newAnimator.AnimationId = "rbxassetid://"..avaibleAnimationIds[1]
local ReleaseAnim = Character:WaitForChild("Humanoid"):WaitFotChild("Animator"):LoadAnimation(newAnimator) -- Creating the animation loader
	if active == true then
		
		ReleaseAnim:Stop()
		
		Event:FireClient(player)
	else	
		
		ReleaseAnim:Play()
		newAnimator:Destroy()
	end
end)

You are loading 2 different animations to the Humanoid Animator, and that is why the first loaded animation doesn’t stop. Also I probably have made some spelling errors, because I am on mobile.


Loading animations on Humanoid is deprecated.

how to put two or more animation in humanoid where you can stop and play the animation you want?

GetPlayingAnimationTracks(), and as a workaround for it being deprecated, you will have to manually insert the animation into a table. With a for loop, you can easily stop the animation.

1 Like