Probably Inefficient Methods For Scripting a Combat System

Let’s start off the bat. So first I don’t know what I’m doing, I don’t think I’m scripting combat properly. Here’s why:

  • When I make a Combo Chain, I use a Number Variable that checks the table for the specified combo number like 1-5 for light attacks. This variable goes up by 1 each time you click, and resets after some time of not clicking, or if it reaches 5. This number gets the id for the animation and plays it.
    e.g
local Combos = {
"rbxassetid://1"; -- animations 
"rbxassetid://2";
"rbxassetid://3";
"rbxassetid://4";
"rbxassetid://5";
}
local ComboNumber = 1
ComboAnimationId = Combos[ComboNumber]
-- Create Animation, Give Id, etc.
  • I fire a function, and add a coroutine wrapped around it that looks reaaally messy. This function is what makes me able to check with a hitbox if anyone is in it after the animation plays for the combo.
    e.g
function CheckHitbox()
coroutine.wrap(function()
-- create a hitbox, then check if anyone's in it.
end)()
end

There are some reasons that the coding looks really Inefficient to me. For the Hitbox I’m using a coroutine when I probably don’t need it, but I’m using it anyways because it could pause the combat so I can’t run it again since the combat system uses a Debounce, or override the next hitbox if ran two times in a row quickly.

Now for the ComboNumber, the reason I find it inefficient is because I believe there’s probably a better way of doing this, but I just don’t know how. I’ve already made it a habit to use a number variable and table for doing this.

I prefer using magnitude instead of hitboxes my combat systems
Hitboxes usually rely on touched events I believe

so you loop through the players and check their magnitude? I used to do that when I first started scripting, but Idk magnitude isnt really all that great when a player’s running away I need something thats stable so even when the players trying to avoid getting hit they can still get hit.

You could use region3 and cast it infront of the player everytime they attack.

From my experience that does work, but it just causes more server lag. But yeah I usually do use that, I know you can also use that one ray module.

The hitbox isn’t really the problem though, I just wanna know if there’s any more efficient methods from the top post.

the magnitude won’t be high so that should enable players to escape from the range