The problem with the air combo

Local script:

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

local uis = game:GetService("UserInputService")
local remote = game:GetService("ReplicatedStorage").Combat

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

local canAir = true

local punchAnims = {
	'rbxassetid://13084044031', -- 1
	'rbxassetid://13084048677', -- 2
	'rbxassetid://13089334504', -- 3
	'rbxassetid://13089335993', -- 4
	'rbxassetid://13089337458', -- 5
}


local airAnims = {
	'rbxassetid://13103638685', -- KICK UP
	'rbxassetid://13103652945', -- KICK DOWN
}

local function hb(size, Cframe, ignore, char)
	local hb = Instance.new("Part", workspace.Fx)
	hb.Anchored = true
	hb.CanCollide = false
	hb.Transparency = 0.6
	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 lasttarg
	
	for i, v in pairs(hb:GetTouchingParts()) do
		if v.Parent:FindFirstChild("Humanoid") and table.find(ignore, v.Parent) == nil then
			if lasttarg then
				if (lasttarg.Position - char.PrimaryPart.Position).Magnitude > (v.Position - char.PrimaryPart.Position).Magnitude then
					lasttarg = v.Parent.PrimaryPart
				end
			else
				lasttarg = v.Parent.PrimaryPart
			end
		end
	end
	
	hb:Destroy()
	if lasttarg then
		return lasttarg.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 == 3 and canAir then
			canAir = false
			animation.AnimationId = airAnims[1]
			air = "Up"
		elseif not uis:IsKeyDown("Space") and combo == 4 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"] = "ml",
			}
			
			remote:FireServer(data)
		end
		
		if combo == #punchAnims then
			combo = 1
			lastM1End = tick()
		else
			combo += 1
		end
		
		humanoid.WalkSpeed = 0
		wait(.4)
		humanoid.WalkSpeed = 13
	end
end)

humanoid.StateChanged:Connect(function(old, new)
	if new == Enum.HumanoidStateType.Landed then
		canAir = true
	end
end)

uis.JumpRequest:Connect(function()
	if tick() - lastTimeM1 < 1 then
		humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
	else
		humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)
	end
end)

Script:

local remote = game:GetService("ReplicatedStorage"):WaitForChild("Combat")

remote.OnServerEvent:Connect(function(client, data)
	if data.Action == "ml" 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)) * 25
			bv.MaxForce = Vector3.new(99999, 99999, 99999)
			bv.Name = "Velocity"
			game.Debris:AddItem(bv, .2)
			
		elseif data.Combo == 5 then
			
			local bv = Instance.new("BodyVelocity", data.Character.PrimaryPart)
			bv.Velocity = data.Character.PrimaryPart.CFrame.LookVector * 10
			bv.MaxForce = Vector3.new(99999, 99999, 99999)
			bv.Name = "Velocity"
			game.Debris:AddItem(bv, .2)
			
			local bv = Instance.new("BodyVelocity", data.Character.PrimaryPart)
			bv.Velocity = data.Character.PrimaryPart.CFrame.LookVector * 75
			bv.MaxForce = Vector3.new(99999, 99999, 99999)
			bv.Name = "Velocity"
			game.Debris:AddItem(bv, .2)
		else
			local bv = Instance.new("BodyVelocity", data.Character.PrimaryPart)
			bv.Velocity = data.Character.PrimaryPart.CFrame.LookVector * 10
			bv.MaxForce = Vector3.new(99999, 99999, 99999)
			bv.Name = "Velocity"
			game.Debris:AddItem(bv, .2)

			local bv = Instance.new("BodyVelocity", data.Character.PrimaryPart)
			bv.Velocity = data.Character.PrimaryPart.CFrame.LookVector * 10
			bv.MaxForce = Vector3.new(99999, 99999, 99999)
			bv.Name = "Velocity"
			game.Debris:AddItem(bv, .2)
		end
	end
end)

So I have two scripts, basically everything more or less works. The only problem is that when the air combo starts, the player tosses, but the NPC does not. Hope for an answer)

Video:

P.S. I’ll tell you right away that anchored is off

In that part of the code, you’re creating two identical body positions and assigning them to the same object. Did you mean to assign one to the NPC?

Yes, I wanted the NPC to go up in the air with me

I commented out the second part of the code you showed me but it didn’t change anything, here’s an example:

            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)

That’s not what I meant, I meant parent the second body position to the NPC instead of the player.

And you can specify what I do and where I do wrong?

In this part of the code, you create two identical body positions. I think you are trying to put one inside the player, which you have done, and put the other in the NPC, which you haven’t done.

1 Like

Whenever you try to combine the movements of 2 humanoids Roblox physics goes nuts.

I’d suggest searching ‘carry player’ or ‘carry NPC’ or similar terms because I’ve seen a few posts over the years dealing with moving 1 humanoid with another humanoid.

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