im brand new to scripting and am following a video on adding a punch animation to my avatar. my avatar is not punching and im lost after using chatgpt and checking every line. heres the code:
local cas = game.GetService("ContextActionService")
local plr = game.Players.LocalPlayer
local character = plr.Character or plr.CharacterAdded:Wait()
local hum = character:WaitForChild("Humanoid")
local animator = hum:WaitForChild("Animator")
local Punch1 = animator:LoadAnimation(script:WaitForChild("Punch1"))
local Punch2 = animator:LoadAnimation(script:WaitForChild("Punch2"))
--add other punches here:
local currentPunch = 0
local debounce = false
local function punch()
if debounce then return end
debounce = true
if currentPunch == 0 then
Punch2:Play()
task.wait(0.4)
debounce = false
elseif currentPunch == 1 then
Punch1:Play()
task.wait(0.4)
debounce = false
elseif currentPunch == 2 then
Punch2:Play()
task.wait(0.8)
debounce = false
end
if currentPunch == 2 then
currentPunch = 0
else
currentPunch += 1
end
end
cas:BindAction("Punch", punch, true, Enum.UserInputType.MouseButton1)