Click combat script wont work as intended

So im making a click combat script, im currently working on the clients side. Im using an intiger value since i want more than 2 clicks, and i have an animation for each click. The script is working but not in the way i intended

I want the script to run like “Click 1, animation 1 play. Click 2, animation 2 play. Click 3, animation 3 play. Wait. Repeat”

Code
local player = game:GetService("Players").LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")

local rPunch = script.Punch2
local lPunch = script.Punch2
local UIS = game:GetService("UserInputService")

local number = 1
local pauseTime = .98
local debounce = false

local TS = game:GetService("TweenService")
local rTrack = hum.Animator:LoadAnimation(rPunch)
local lTrack = hum.Animator:LoadAnimation(lPunch)

UIS.InputBegan:Connect(function(input, chat)
	if chat then return end
	
	if input.UserInputType == Enum.UserInputType.MouseButton1 and not debounce then
		debounce = true
		if number == 1 then
			rTrack:Play()
			wait(.5)
			number = 2
			print(number)
		elseif number == 2 then
			lTrack:Play()
			wait(.5)
			number = 3
			print(number)
		elseif number == 3 then
			rTrack:Play()
			wait(4)
			number = 1
			print(number)
		end
		wait(3)
		debounce = false
	end
end)

for some reason its only playing 1 animation, so im assuming only part of the code is running.

Help and feedback is appreciated, thank you for your time :smiley:

Are there any errors in the output?

Nope, no errors at all (gjvgjvbgjgjvgj)

There are a few things that I don’t like about this script

no. 1 is how the animations are being loaded into the player humanoid. Typically you do Humanoid:LoadAnimation(Animation) not Humanoid.Animator:LoadAnimation(Animation)

no. 2 is how inefficient you play the animations. Because to used a if elseif statement you will have to type in every animation. I would have the animations in a array/table which then can be accessed, played and updated without much hassle.

Whats an arraytable? Ive never heard of that lol. is there an article i can read on it so i can better use it?

Someone told me Humanoid:LoadAnimation() was being depricated :sweat_smile:

EDIT: I just re-read the quote and i see what you mean now. I understand. But im still lost on how i can fix my issue? the same animation is playing over and over again and i tried replacing the IDs but nothing has changed

Can you show the output log? That might help determine what is going on.

There are no errors tho :sweat_smile:

Yes you are right. I’m an old scripter and wasn’t aware of the change

Are you sure the animations aren’t the same?

1 Like

I just checked! turns out they were the same :sweat_smile:

Actually you are meant to load them throught the animator, not the humanoid: Deprecating LoadAnimation on Humanoid and AnimationController