Here's my script:

player = game.Players.LocalPlayer
hum = player.Character.Humanoid

mouse = player:GetMouse()

animation1 = script:WaitForChild("One")
animation2 = script:WaitForChild("Two")
animation3 = script:WaitForChild("Three")
animation4 = script:WaitForChild("Four")

function endOne()
	local oneTrack = hum:LoadAnimation(animation1)
	oneTrack:Stop()
	print('animation1 successfully stopped!')
end

function endTwo()
	local twoTrack = hum:LoadAnimation(animation2)
	twoTrack:Stop()
	print('animation2 successfully stopped!')
end

function endThree()
	local threeTrack = hum:LoadAnimation(animation3)
	threeTrack:Stop()
	print('animation3 successfully stopped!')
end

function endFour()
	local fourTrack = hum:LoadAnimation(animation4)
	fourTrack:Stop()
	print('animation4 successfully stopped!')
end

enabled = true

mouse.KeyDown:connect(function(key)
	if key == "e" then -- Animation 1
		if enabled then
			enabled = false
			
			endTwo()
			endThree()
			endFour()
			wait()
			
			local animationTrack = hum:LoadAnimation(animation1)
			animationTrack:Play()
			
			wait(2)
			enabled = true
		end
	end
end)

mouse.KeyDown:connect(function(key)
	if key == "r" then -- Animation 2
		if enabled then
			enabled = false 
			
			endOne()
			endThree()
			endFour()
			wait()
		
			local animationTrack = hum:LoadAnimation(animation2)
			animationTrack:Play()
			
			wait(2)
			enabled = true
		end
	end
end)

mouse.KeyDown:connect(function(key)
	if key == "t" then -- Animation 3
		if enabled then
			enabled = false
			
			endOne()
			endTwo()
			endFour()
			wait()
		
			local animationTrack = hum:LoadAnimation(animation3)
			animationTrack:Play()
			
			wait(2)
			enabled = true
		end
	end
end)

mouse.KeyDown:connect(function(key)
	if key == "y" then -- Animation 4
		if enabled then

			local animationTrack = hum:LoadAnimation(animation4)
			animationTrack:Play()
			
			wait(2)
			enabled = true
		end
	end
end)

mouse.KeyDown:connect(function(key)
	if key == "w" then -- Stop all animations / back to normal
		if enabled then
			endOne()
		end
	end
end)

Thank you :)

2 comments

0

The character and humanoid probably haven't loaded yet. Can't type a full answer right now, sorry. Basically you need to wait for them to exist before defining them.

0

okay thank you so much Perci1 :) Bless u bro God loves you SO MUCH :D