Combat System Not Working When I Change The Animations

I Basically followed a tutorial and achieved a similar combat to stbg, but the only problem i’m facing rn is changing the initial animations provided.

When I change the second punch’s animation id for example, The first one runs normally, until the second one it runs the other animation but doesnt run any hitbox or nothing and i just cant hit ever again, and this applies if i change the first or the third or the fourth.

I have tried to make the diff animation the same length and the same name when published but it just doesnt work and I suspect it has someting to do with my script:

Here is the server script:

local rp = game:GetService(“ReplicatedStorage”)
local remotes = rp:WaitForChild(“Remotes”)
local player = game.Players.PlayerAdded:Wait()
local punchEvent = remotes:WaitForChild(“Punch”)
local char = player.CharacterAdded:Wait() or player.Character
local ss = game:GetService(“ServerStorage”)
local modules = ss:WaitForChild(“Modules”)
local frontDashOccurred = false
local upperParticleEvent = remotes:WaitForChild(“UppercutParticle”)

local MuchachoHitbox = require(modules:WaitForChild(“MuchachoHitbox”))
local ragdollHandler = require(modules:WaitForChild(“RagdollFolder”):WaitForChild(“ModuleScript”))
local hitService = require(modules:WaitForChild(“HitService”))

local soundService = game:GetService(“SoundService”)

local animations = rp:WaitForChild(“Anims”)
local punchAnims = animations:WaitForChild(“Combat”)

punchAnims.Punch2.AnimationId = “rbxassetid://16223986794”

local damagedAnims = animations:WaitForChild(“Damaged”)
local otherAnims = animations:WaitForChild(“Other”)

local debris = game:GetService(“Debris”)

local lastPunch = {}

local MAX_COMBO = 4
local frontDash = char:GetAttribute(“LongDash”)

local function stopAnimations(object)
for i,v in pairs(object:GetPlayingAnimationTracks()) do
v:Stop()
end
end

local function changeCombo(character)
local combo = character:GetAttribute(“Combo”)

local player = game:GetService("Players"):GetPlayerFromCharacter(character)

if combo == MAX_COMBO  then
	character:SetAttribute("Combo",1)

else
	if lastPunch[player] then
		local passedTime = tick()  - lastPunch[player]

		if passedTime <= 1.3 and not frontDashOccurred then
			character:SetAttribute("Combo",combo+1)
		else
			character:SetAttribute("Combo",1)

		end
	else
		character:SetAttribute("Combo",1)
	end
end
lastPunch[player] = tick()

end
local function getPunchAnim(character, tryToJump)
local distance = 0
local combo = character:GetAttribute(“Combo”)

local hum = character:WaitForChild("Humanoid")

if combo == MAX_COMBO then
	if hum:GetState() == Enum.HumanoidStateType.Freefall then
		local downSlam = otherAnims:WaitForChild("DownSlam")
		return downSlam
	elseif tryToJump then
		hum.JumpHeight = 0
		local upperCut = otherAnims:WaitForChild("Uppercut")
		return upperCut

	end
end

local currAnim = punchAnims:GetChildren()[combo]

return currAnim

end

local function getDamagedAnim(character)
local combo = character:GetAttribute(“Combo”)

local hum = character:WaitForChild("Humanoid")

local currAnim = damagedAnims:GetChildren()[combo]

return currAnim

end
local LastPunch = {}
punchEvent.OnServerEvent:Connect(function(player,jump,frontDashOccurring)
local currentTime = tick()

if not LastPunch[player] then
	LastPunch[player] = 0
end

local char = player.Character
local hum = char:WaitForChild("Humanoid")
local humRp = char:WaitForChild("HumanoidRootPart")
frontDashOccurred = frontDashOccurring
local attacking = char:GetAttribute("Attacking")
local punching = char:GetAttribute("Punching")
local longDash = char:GetAttribute("Dashing")
local stunned = char:GetAttribute("Stunned")

local blocking = char:GetAttribute("Blocking")
local bypass = char:GetAttribute("Bypass")
if bypass then
	if attacking or longDash or punching or blocking or currentTime - LastPunch[player]<0.39 then return end
else
	if attacking or stunned or longDash or punching or blocking or currentTime - LastPunch[player]<0.39 then return end
end

LastPunch[player] = currentTime
char:SetAttribute("Attacking",true)
char:SetAttribute("Punching",true)

stopAnimations(hum)
changeCombo(char)

hum.WalkSpeed = 7
hum.JumpHeight = 0

local currAnim = getPunchAnim(char, jump)
local currDamagedAnim = getDamagedAnim(char)

local playPunch = hum:LoadAnimation(currAnim)

local hitbox = MuchachoHitbox.CreateHitbox()
hitbox.Size = Vector3.new(5,4,5)
hitbox.CFrame = humRp
hitbox.Offset = CFrame.new(0,0,-3.5)
hitbox.Visualizer = true
--	hitbox.AutoDestroy = false

local ragdoll = false
local downslam = false
local uppercut = false
local touch = false
local frontDash = false
frontDashOccurred = false

local hitboxDuration = 0.1
if currAnim.Name == "Uppercut" then
	uppercut = true	
	hitboxDuration = 0.25
elseif currAnim.Name == "DownSlam" then
	downslam = true
	hitboxDuration = 0.25
end
hitbox.Touched:Connect(function(hit, humanoid)
	local humanoid = hit.Parent:FindFirstChildOfClass("Humanoid")
	if humanoid ~= hum then
		touch = true
		local enemyChar = humanoid.Parent
		local enemyHumRp = humanoid.Parent:FindFirstChild("HumanoidRootPart")
		if char:GetAttribute("Combo") == MAX_COMBO then
			local kb = humRp.CFrame.LookVector * 30 + Vector3.new(0,17,0)
			if uppercut then
				kb = Vector3.new(0,40,0)
			elseif downslam then
				local currSound = soundService:WaitForChild("SFX")["GroundSlam"]:Clone()
				currSound.Parent = humRp
				currSound:Play()
				debris:AddItem(currSound,1)
				enemyHumRp.CFrame *= CFrame.Angles(math.rad(-90),0,0)
				kb = Vector3.new(0,-10,0)
			end
			local currSound = soundService:WaitForChild("Punch"):GetChildren()[char:GetAttribute("Combo")]:Clone()
			currSound.Parent = humRp
			currSound:Play()	hitService.Hit(humanoid,5,1.9,kb,true,enemyChar:GetAttribute("Blocking"),downslam,char,currDamagedAnim)
		else
			local currSound = soundService:WaitForChild("Punch"):GetChildren()[char:GetAttribute("Combo")]:Clone()
			currSound.Parent = humRp
			currSound:Play()

			debris:AddItem(currSound,1)

			local bv = Instance.new("BodyVelocity")
			bv.MaxForce = Vector3.new(1,1,1) * math.huge
			bv.P = 10000
			bv.Velocity = humRp.CFrame.LookVector * 9
			bv.Parent = humRp

			debris:AddItem(bv,0.2)
			hitService.Hit(humanoid,5,0.8,humRp.CFrame.LookVector * 10,false,enemyChar:GetAttribute("Blocking"),downslam,char,currDamagedAnim)
		end
	end
end)
playPunch.KeyframeReached:Connect(function(kf)
	if kf == "Hit" then
		if char:GetAttribute("Stunned") then
			return
		end
		task.spawn(function()
			char:SetAttribute("Attacking",false)
			if char:GetAttribute("Combo") == MAX_COMBO then
				task.wait(1.35)
			end
			char:SetAttribute("Punching",false)
		end)
		hitbox:Start()
		task.wait(hitboxDuration)
		hitbox:Stop()
		--			hitbox:Destroy()

		if char:GetAttribute("Combo") == MAX_COMBO then
			if not touch then
				hum.WalkSpeed = 0
				hum.JumpHeight = 0
				task.delay(0.5,function()
					wait(0.3)
					hum.WalkSpeed = 16
					hum.JumpHeight	 = 7.2
				end)
			end
		end
	end
end)
local isPlaying = false
playPunch.Stopped:Connect(function()
	if char:GetAttribute("Combo") == MAX_COMBO then
		if touch then
			wait(0.3)
			hum.WalkSpeed = 16
			hum.JumpHeight = 7.2
		end
	else
		wait(0.3)
		hum.WalkSpeed = 16
		hum.JumpHeight = 7.2
	end
end)
local upperCut = otherAnims:WaitForChild("Uppercut")
local downSlam = otherAnims:WaitForChild("DownSlam")
playPunch:Play()
isPlaying = true
if currAnim == upperCut then
	playPunch:AdjustSpeed(0.7)
	task.delay(0.9, function() -- Adjust the delay duration as needed
		isPlaying = true
	end)
elseif currAnim == downSlam then
	playPunch:AdjustSpeed(1.75)

elseif currAnim.Name == "Punch4" or "Punch3" then
	playPunch:AdjustSpeed(1.5)
else
	playPunch:AdjustSpeed(1.9)
end
playPunch.Stopped:Connect(function()
	isPlaying = false
	hum.JumpHeight = 7.2
	hum.WalkSpeed = 16
end)
while isPlaying and currAnim ~= upperCut do
	hum.JumpHeight = 0
	task.wait()
end
while isPlaying and currAnim == upperCut do
	hum.JumpHeight = 0
	hum.WalkSpeed = 5
	task.wait() 
end

end)

Here’s the client script:

local rp = game:GetService(“ReplicatedStorage”)
local remotes = rp:WaitForChild(“Remotes”)
local player = game:GetService(“Players”).LocalPlayer
player.CharacterAdded:Wait()
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild(“Humanoid”)
local humRp = char:WaitForChild(“HumanoidRootPart”)
local camera = workspace.CurrentCamera
local punchEvent = remotes:WaitForChild(“Punch”)
local animations = rp:WaitForChild(“Anims”)
local punchAnims = animations:WaitForChild(“Combat”)
local UIS = game:GetService(“UserInputService”)
local mouseButtonDown = false – Flag to keep track of whether the mouse button is down
local function punchWhileMouseDown()
while mouseButtonDown do
hum.JumpHeight = 0
local tryToJump = UIS:IsKeyDown(Enum.KeyCode.Space)
punchEvent:FireServer(tryToJump)
task.wait(0.34) – Adjust the delay between each punch as needed
end
end

UIS.InputBegan:Connect(function(input, isTyping)
if isTyping then return end
local tryToJump = UIS:IsKeyDown(Enum.KeyCode.Space)
local currAnim = hum:GetPlayingAnimationTracks()
– Check if the left mouse button is pressed
if input.UserInputType == Enum.UserInputType.MouseButton1 then
mouseButtonDown = true – Set the flag to true
task.spawn(punchWhileMouseDown) – Start punching while the mouse button is down
end
end)

UIS.InputEnded:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
hum.JumpHeight = 7.2
mouseButtonDown = false – Set the flag to false when the mouse button is released
end
end)

and here is a video of the problem im currently facing:

Most likely there is additional places where you need to update the animation IDs. Open any player/dummy animating scripts and search for the sanitized id - update that number as well.

^ Easy if you use VS and Roblox > Rojo export you can search every script at once but the hard way will get it done.

Nvm I figured it out , I jsut had to put an animation even with the name “Hit” in the new animation.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.