Animation only playing when my animate script is disabled?

Punching animations that play over the run animations

Basically, I have animations for punching that ONLY work when the animate script is disabled. This could be because my walk and run animations are interfering, but they are set to movement and not action. The punches are set to action

Ive tried multiple solutions, asking claude, chatgpt, roblox developers discord, nothing has worked.

local CombatModule = {}

--//Services
local RS = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")

--//Objects
local punchCooldowns = {}

local animCombo = {
	["One"] = RS.Animations.Mechanics.Punch1,
	["Two"] = RS.Animations.Mechanics.Punch2,
	["Three"] = RS.Animations.Mechanics.Punch3,
	["Four"] = RS.Animations.Mechanics.Punch4,
	["Five"] = RS.Animations.Mechanics.Kick
}

--//Functions
local Settings = {
	Hitbox = {
		Size = Vector3.new(5,5,5),
		BrickColor = BrickColor.Red(),
		Transparency = 0.5,
		damageAmount = 10,
		Duration = 0.3, -- hw long the hitbox stays active
		StartDelay = 0.1, -- Ddlay before hitbox becomes active (let animation play first)
	},

	NormalCooldown = 0.9,
	ComboResetTime = 0.9,
	ComboCooldown = 0.18,
}

-- combo tracking
local comboIndex = {}
local lastPunchTime = {}
local lastTargetHumanoid = {}

local function stabilizedKnockback(char, dir, speed, time)
	local root = char:FindFirstChild("HumanoidRootPart")
	if not root then 
		warn("No HumanoidrootPart for knockback")
		return 
	end

	dir = Vector3.new(dir.X, 0, dir.Z)
	if dir.Magnitude < 0.01 then 
		warn("Direction too small for knockback")
		return 
	end

	-- make sure the root isnt anchored
	if root.Anchored then
		warn("Root is anchored, cant apply knocback")
		return
	end

	-- stabilizer
	local att0 = Instance.new("Attachment")
	att0.Parent = root

	local align = Instance.new("AlignOrientation")
	align.Attachment0 = att0
	align.RigidityEnabled = true
	align.MaxTorque = 1e9
	align.Responsiveness = 200
	align.CFrame = CFrame.lookAt(root.Position, root.Position + root.CFrame.LookVector)
	align.Parent = root

	-- apply knockback velocity
	local knockbackVelocity = dir.Unit * speed
	root.AssemblyLinearVelocity = Vector3.new(knockbackVelocity.X, root.AssemblyLinearVelocity.Y, knockbackVelocity.Z)

	print("Applied knockback:", knockbackVelocity, "to", char.Name)

	task.delay(time or 0.2, function()
		if align and align.Parent then
			align:Destroy()
		end
		if att0 and att0.Parent then
			att0:Destroy()
		end
	end)
end

function CombatModule.OnLeave(plr)
	punchCooldowns[plr.Name] = nil
	comboIndex[plr.Name] = nil
	lastPunchTime[plr.Name] = nil
	lastTargetHumanoid[plr.Name] = nil
	print("Player",plr.Name.." left, punch cooldowns reset.")
end

function CombatModule.PunchInit(player)
	if punchCooldowns[player.Name] == true then 
		print("Punch on cooldown for", player.Name)
		return 
	end

	-- combo step selection
	local now = os.clock()
	local last = lastPunchTime[player.Name]

	if (not last) or (now - last > Settings.ComboResetTime) then
		comboIndex[player.Name] = 1
	else
		comboIndex[player.Name] = (comboIndex[player.Name] or 1)
	end

	lastPunchTime[player.Name] = now
	local step = comboIndex[player.Name]

	local comboKey =
		(step == 1 and "One")
		or (step == 2 and "Two")
		or (step == 3 and "Three")
		or (step == 4 and "Four")
		or "Five"

	print("Executing combo step:", comboKey, "for", player.Name)

	--variables
	local character = player.Character
	local humanoid = character and character:FindFirstChildOfClass("Humanoid")
	local rootpart = character and character:FindFirstChild("HumanoidRootPart")

	if not character or not humanoid or not rootpart then 
		warn("Missing character components for", player.Name)
		return 
	end

	-- load and play anims
	local Animator = humanoid:FindFirstChildOfClass("Animator")
	if not Animator then
		Animator = Instance.new("Animator")
		Animator.Parent = humanoid
		print("Created new Animator for", player.Name)
	end

	local animToLoad = animCombo[comboKey]
	if not animToLoad then
		warn("Animation not found for combo key:", comboKey)
		return
	end

	local Animation = Animator:LoadAnimation(animToLoad)
	Animation.Priority = Enum.AnimationPriority.Action4 -- higher then damn walk anim
	Animation:Play(0.15)

	print("Playing animation:", animToLoad.Name or animToLoad.AnimationId, "for", player.Name)

	-- track who plr hit
	local hitHum = nil
	local alreadyHit = {} -- prevent hitting the same target twice in a punch

	-- wait for anim before hitbox
	task.wait(Settings.Hitbox.StartDelay)

	-- make hitbox (visual debug)
	local hitbox = Instance.new("Part")
	hitbox.Size = Settings.Hitbox.Size
	hitbox.BrickColor = Settings.Hitbox.BrickColor
	hitbox.Transparency = 0.5
	hitbox.Anchored = true
	hitbox.CanCollide = false
	hitbox.Parent = workspace
	hitbox.Name = player.Name .. "_Hitbox"

	-- hitbox detection
	local startTime = tick()
	local hitConnection

	hitConnection = RunService.Heartbeat:Connect(function()
		local elapsed = tick() - startTime

		-- stop after debounce
		if elapsed > Settings.Hitbox.Duration then
			hitConnection:Disconnect()
			hitbox:Destroy()
			return
		end

		-- update hitbox position to follow player
		if not rootpart or not rootpart.Parent then
			hitConnection:Disconnect()
			hitbox:Destroy()
			return
		end

		hitbox.CFrame = rootpart.CFrame * CFrame.new(0, 0, -4)

		-- check for hits
		local params = OverlapParams.new()
		params.FilterType = Enum.RaycastFilterType.Exclude
		params.FilterDescendantsInstances = {character}

		local parts = workspace:GetPartsInPart(hitbox, params)

		for _, part in ipairs(parts) do
			local model = part:FindFirstAncestorOfClass("Model")
			local targetHumanoid = model and model:FindFirstChildOfClass("Humanoid")

			if targetHumanoid and targetHumanoid ~= humanoid and not alreadyHit[targetHumanoid] then
				alreadyHit[targetHumanoid] = true
				hitHum = targetHumanoid

				print("Hit detected on:", model.Name)

				local targetRoot = model:FindFirstChild("HumanoidRootPart")
				if targetRoot then
					local direction = (targetRoot.Position - rootpart.Position)

					print("Knockback direction:", direction)

					-- play hit anim
					local targetAnimator = targetHumanoid:FindFirstChildOfClass("Animator")
					if not targetAnimator then
						targetAnimator = Instance.new("Animator")
						targetAnimator.Parent = targetHumanoid
					end

					local hitAnim = RS.Animations.Mechanics.Hit4
					local hitTrack = targetAnimator:LoadAnimation(hitAnim)
					hitTrack.Priority = Enum.AnimationPriority.Action4 -- high priority
					hitTrack:Play(0.05)

					-- apply damage and knockback
					targetHumanoid:TakeDamage(Settings.Hitbox.damageAmount)
					stabilizedKnockback(model, direction, 25, 0.2)
				end
			end
		end
	end)

	-- advance combo for next punch
	if step >= 5 then
		comboIndex[player.Name] = 1
	else
		comboIndex[player.Name] = step + 1
	end

	-- cooldown logic
	punchCooldowns[player.Name] = true

	local cd = Settings.NormalCooldown

	if hitHum then
		local sameTarget = (lastTargetHumanoid[player.Name] == hitHum)
		local now2 = os.clock()
		local inComboWindow = (last ~= nil) and ((now2 - last) <= Settings.ComboResetTime)

		if sameTarget and inComboWindow then
			cd = Settings.ComboCooldown
			print("Using combo cooldown:", cd)
		else
			print("Using normal cooldown:", cd)
		end

		lastTargetHumanoid[player.Name] = hitHum
	end

	task.delay(cd, function()
		punchCooldowns[player.Name] = false
		print("Cooldown finished for", player.Name)
	end)
end

return CombatModule
```![20260106-0717-03.7655889|video](upload://cjnrWvPDaLrwBimoqQI3C6wlgl9.mp4)
1 Like