What's the most efficient way to code a combat system



This is my answer, I think it’s probably the most efficient way of doing it.

local Animations = {
  Animation1 = {
    ["ID"] = 123456789,
    ["BodyPart"] = BodyPart1
  Animation2 = {
     ["ID"] = 123456789,
     ["BodyPart"] = BodyPart2
   Animation3 = {
     ["ID"] = 123456789,
     ["BodyPart"] = BodyPart3

-- Put this in the event
local AnimationIndex = {}

for Index in Animations do
       if Index then
              table.insert(AnimationIndex, Index)

local RandomIndex = AnimationIndex[math.random(1, #AnimationIndex)]

local anim = Instance.new('Animation')
Animatiom.AnimationId = "rbxassetid://" .. Animations[AnimationIndex]["ID"]
local LoadedAnimation = Humanoid:LoadAnimation(Animation)

local Clone = DamageScript:Clone()
Clone.Parent = BodyPart


I had issues with .Touched when I handled it on the client. I tried it out on the server and some finnicky behavior such as a part with the listener attached obviously hitting another player (on the client’s machine too) but nothing detected. On the server, although there is some added overhead, I’ve found hit detection to be much better.