Punch Animations/Punch Damage

Heyo, I’ve been trying to follow a tutorial for making a combat system, since I’m trying to get into making a melee game, however, only the first punch animation is played, but occasionally the others do to. It also only deals damage to yourself, which I don’t want, and doesn’t deal damage to anyone else. What is wrong in the scripts? Link to the youtube video I followed: Roblox Advanced Combat System Tutorial Part 1 - YouTube

LocalScript-

local character = script.Parent
local player = game.Players.LocalPlayer
local humanoid = character:FindFirstChild("Humanoid")


local uis = game:GetService("UserInputService")

local remote = game.ReplicatedStorage:WaitForChild("CombatEvent")

local lastTimeM1 = 0
local lastM1End = 0
local combo = 1

local canAir = true

local punchAnims = {
	
	'rbxassetid://10506078364', --1
	'rbxassetid://10506088664', --2
	'rbxassetid://10506090805', --3
	'rbxassetid://10506092313', --4
	'rbxassetid://10506094809', --5
	
}

local airAnims = {
	
	'rbxassetid://10506090805', --Launcher
	'rbxassetid://10506103953', --DownSlam
	
}

local function hb(size,cframe,ignore,char)
	local hb = Instance.new("Part",workspace.FX)
	hb.Anchored = true
	hb.CanCollide = false
	hb.Transparency = 1
	hb.Name = "hb"
	hb.Material = Enum.Material.ForceField
	hb.CanQuery = false
	hb.Size = size
	hb.CFrame = cframe
	
	local con
	con = hb.Touched:Connect(function()
		con:Disconnect()
		
	end)
	
	
	local lastarg
	
	for i,v in pairs(hb:GetTouchingParts()) do
		if v.Parent:FindFirstChild("Humanoid") and table.find(ignore, v.Parent) == nil then
			if lastarg then
				if (lastarg.Position - char.PrimaryPart.Position).Magnitude > (v.Position - char.PrimaryPart.Position) then
					lastarg = v.Parent.PrimaryPart
				end
			end
		else
			lastarg= v.Parent.PrimaryPart
		end
	end


	hb:Destroy()
if lastarg then
	return lastarg.Parent
	
else 
	return nil
end
end

uis.InputBegan:Connect(function(input, gpe)
	if gpe then return end
	if input.UserInputType == Enum.UserInputType.MouseButton1 and tick() - lastTimeM1 > .3 and tick() - lastM1End > .7 then
		if tick() - lastTimeM1 > .7 then
			combo = 1
		end
		
		lastTimeM1 = tick()
		
		local animation = Instance.new("Animation", workspace.FX)
		local air = nil
		
		if uis:IsKeyDown("Space") and combo == 4 and canAir then
			canAir = false
			animation.AnimationId = airAnims(1)
			air = "Up"
		elseif not uis:IsKeyDown("Space") and combo == 5 and not canAir then
			animation.AnimationId = airAnims(2)
			air = "Down"
		else 
			animation.AnimationId = punchAnims[combo]
		end
		
		local load = humanoid:LoadAnimation(animation)
		load:Play()
		
		animation:Destroy()
		
		local hitTarg = hb(Vector3.new(4,6,4), character.PrimaryPart.CFrame * CFrame.new(0,0,-3), {character}, character)
		
		if hitTarg then
			local data = {
				
				["Target"] = hitTarg,
				["Character"] = character,
				["Combo"] = combo,
				["Air"] = air,
				["Action"] = "m1",
				
			}
			
			remote:FireServer(data)
		end
		
		if combo == #punchAnims then
			combo = 1
			lastM1End = tick()
		else
			combo += 1
		end
		humanoid.WalkSpeed = 0
		load.Stopped:Wait(.1)
		humanoid.WalkSpeed = 25
	end
end)

ServerScript-

local remote = game.ReplicatedStorage:FindFirstChild("CombatEvent")

remote.OnServerEvent:Connect(function(client, data)
	if data.Action == "m1" then
		data.Target.Humanoid:TakeDamage(5)
		
		if data.Air == "Up" then
			local bp = Instance.new("BodyPosition")
			bp.Position = data.Character.PrimaryPart.Position + Vector3.new(0,30,0)
			bp.P = 1200
			bp.MaxForce =  Vector3.new(99999,99999,99999)
			bp.D = 200
			bp.Name = "Position"
			bp.Parent = data.Character.PrimaryPart
			game.Debris:AddItem(bp,1)
			
			local bp = Instance.new("BodyPosition")
			bp.Position = data.Character.PrimaryPart.Position + Vector3.new(0,30,0)
			bp.P = 1200
			bp.MaxForce =  Vector3.new(99999,99999,99999)
			bp.D = 200
			bp.Name = "Position"
			bp.Parent = data.Character.PrimaryPart
			game.Debris:AddItem(bp,1)
		elseif data.Air == "Down" then
			for i,v in pairs(data.Target.PrimaryPart:GetChildren()) do
				if v:IsA("BodyMover") then
					v:Destroy()
				end
			end
			local bv = Instance.new("BodyVelocity", data.Target.PrimaryPart)
			bv.Velocity = (data.Character.PrimaryPart.CFrame.LookVector * 1 - Vector3.new(0,2,0)) * 10
			bv.MaxForce = Vector3.new(99999,99999,99999)
			bv.Name = "Velocity"
			game.Debris:AddItem(bv,.2)
			local bv = Instance.new("BodyVelocity", data.Target.PrimaryPart)
			bv.Velocity = (data.Character.PrimaryPart.CFrame.LookVector * 1 - Vector3.new(0,2,0)) * 75
			bv.MaxForce = Vector3.new(99999,99999,99999)
			bv.Name = "Velocity"
			game.Debris:AddItem(bv,.2)
			
		else
			local bv = Instance.new("BodyVelocity", data.Target.PrimaryPart)
			bv.Velocity = (data.Character.PrimaryPart.CFrame.LookVector * 1 - Vector3.new(0,2,0)) * 10
			bv.MaxForce = Vector3.new(99999,99999,99999)
			bv.Name = "Velocity"
			game.Debris:AddItem(bv,.2)
			local bv = Instance.new("BodyVelocity", data.Target.PrimaryPart)
			bv.Velocity = (data.Character.PrimaryPart.CFrame.LookVector * 1 - Vector3.new(0,2,0)) * 10
			bv.MaxForce = Vector3.new(99999,99999,99999)
			bv.Name = "Velocity"
			game.Debris:AddItem(bv,.2)
		end
	end
end)
1 Like

Those are deprecated use LinearVelocity and AngularVelocity