Combat assistance? I want to make it far more dynamic

Hello there. Today I come on the devforum for once, not about an issue, but instead about possible ways I can further improve my combat so I gain the ability dynamically use the combat, and not purely using a single module that is very static and doesn’t allow for much flexibility.

function CombatHandler.NormalCombat(Player, Character, Humrp, Count, DMG, Char)
	local Character = Player.Character
	local Hum = Character.Humanoid
	local animtracks = Player.Character.Humanoid:GetPlayingAnimationTracks()

	local Folder = Instance.new("Folder")
	Folder.Name = Player.Name.."Folder"
	Folder.Parent = workspace
	Debris:AddItem(Folder, 0.4)

	local Hitbox = Meshes.Hitbox:Clone()
	Hitbox.Parent = Folder
	Hitbox.CFrame = Humrp.CFrame * CFrame.new(0,0,-2)
	
	local Weld = Instance.new("WeldConstraint")
	Weld.Part0 = Hitbox
	Weld.Part1 = Humrp
	Weld.Parent = Weld.Part0
	
	local Whitelist = OverlapParams.new()
	Whitelist.FilterType = Enum.RaycastFilterType.Whitelist
	Whitelist.FilterDescendantsInstances = {workspace.PlayerHitboxes}
	
	
	local Detection	= workspace:GetPartBoundsInBox(Hitbox.CFrame, Hitbox.Size, Whitelist)
	Debris:AddItem(Hitbox, 0.4)
	for i, playerss in pairs(Detection) do
		if playerss and playerss:FindFirstChildOfClass("ObjectValue") and playerss.Char.Value ~= Character then
			local eChar = playerss.Char.Value
			local enemyHum = eChar.Humanoid
			
			if eChar:GetAttribute("IsBlocking") == true then
				DMG = DMG/5
			end
			
			if eChar:GetAttribute("IsBlocking") and Count == 4 then
				eChar:SetAttribute("IsBlocking", false)
				local BV = Instance.new("BodyVelocity", eChar.HumanoidRootPart)
				BV.MaxForce = Vector3.new(22500, 22500, 22500)
				BV.P = 33300
				BV.Velocity = Character.HumanoidRootPart.CFrame.LookVector * 40
				Debris:AddItem(BV, 0.005)	
				coroutine.wrap(function()
					CS:AddTag(eChar, "GuardBroken")
					if CS:HasTag(eChar, "GuardBroken") then
						print("TAGGED!")
						for _,v in pairs(animtracks) do
							v:Stop()
						end
						enemyHum.Animator:LoadAnimation(CombatHandler.Misc[1]):Play()
					end
					enemyHum.WalkSpeed = 0
					enemyHum.JumpPower = 0
				end)()
				
			end
			
			if CS:HasTag(Player.Character, "Stun") or CS:HasTag(Player.Character, "GuardBroken") or Player.Character:GetAttribute("IsBlocking") == true then
				return
			end

			enemyHum:TakeDamage(DMG)
			
			coroutine.wrap(function()
				CS:AddTag(eChar, "Stun")
				enemyHum.WalkSpeed = 2
				enemyHum.JumpPower = 2
			end)()
			

			if eChar:GetAttribute("IsBlocking") == false then
				enemyHum.Animator:LoadAnimation(CombatHandler.HitReaction[Count]):Play()
			end




			MM.DelayControl(eChar, "Stun", .9*2, enemyHum, 13, 50.125)
			MM.DelayControl(eChar, "GuardBroken", 5, enemyHum, 13, 50.125)
			MM.DelayControl(Character, "Dazed", 3, Hum, 13, 50.125)



			--Knock-Back--
			if Count == 4  then
				local BV = Instance.new("BodyVelocity", eChar.HumanoidRootPart)
				BV.MaxForce = Vector3.new(100000, 22500, 100000)
				BV.P = 33300
				BV.Velocity = Character.HumanoidRootPart.CFrame.LookVector * 40
				Debris:AddItem(BV, 0.25)
			
			end
		end
	end
end
3 Likes

You can use ipairs() if you are working with a array (numerical index), its much more faster than pairs() for these cases (but ipairs() not work for dictionaries). Too replace the “i” variable for “_” (placeholder) if you are not using it

This is all, I do not see another possible improvement by a superficial view. Good coding ^^

1 Like