i’m making a fighter and, i used a hitbox system my friend worked on and i tweaked it heavily. I was unpleased with the performance after doing ~20 attacks, so i was wondering what you guys suggest adding / changing to make this hitbox system more performant.
CODE -
-- services --
local players = game:GetService("Players")
local runservice = game:GetService("RunService")
-- objects --
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local remotes = game:GetService("ReplicatedStorage").remotes
local hitbox = remotes.Hitbox
-- variables --
local connection
-- modules --
local region_module = require(game.ReplicatedStorage.modules.REGION_MODULE)
local hitbox_module = require(game.ReplicatedStorage.modules.HITBOX_MODULE)
-- events --
connection = hitbox.OnClientEvent:Connect(function(region,duration,cframe,dmg)
local stopped_attack = false
repeat runservice.Stepped:Wait()
local target_hit = false
local enemy_hum
if not enemy_hum then
for i,v in ipairs(region_module:CastRegion(character,1,region)) do
if v.Parent and v.Parent:FindFirstChildOfClass("Humanoid") and (v.Parent:FindFirstChild("Torso")) then
enemy_hum = v.Parent:FindFirstChildOfClass("Humanoid")
end
end
end
if enemy_hum and enemy_hum.Health > 0 and enemy_hum.Parent:FindFirstChildOfClass('ForceField') == nil and not players:GetPlayerFromCharacter(enemy_hum.Parent) then
local results = hitbox_module:HITBOX(nil,cframe,dmg,enemy_hum,player,duration)
if results then
connection:Disconnect()
target_hit = true
--[[local bvelo = Instance.new("BodyVelocity")
bvelo.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
bvelo.Velocity = CFrame.new(enemy_hum.Parent.Torso.Position - (enemy_hum.Parent.Torso.Position - character.HumanoidRootPart.Position).unit*3,enemy_hum.Parent.Torso.Position).lookVector*25
bvelo.Parent = enemy_hum.Parent.Torso
Debris:AddItem(bvelo,.2)]]--
end
return results
end
until stopped_attack == true or target_hit == true
spawn(function()
wait(duration)
connection:Disconnect()
stopped_attack = true
end)
end)