Barrage Hitbox lags alot whats alternative?
Hello, I have been working on a barrage system but I don't really know how to make the hitbox this is my current hitbox but its extremely lagy and destroys all fps
01 | local function Detected(char) |
03 | local hitbox = script.Meshes.HitBox:Clone() |
04 | hitbox.CFrame = char.HumanoidRootPart.CFrame * CFrame.new( 0 , 0 ,- 2 ) |
05 | hitbox.Parent = game.Workspace |
06 | game.Debris:AddItem(hitbox,. 08 ) |
09 | local weld = Instance.new( "ManualWeld" ) |
11 | weld.Part 1 = char.HumanoidRootPart |
12 | weld.C 0 = weld.Part 0. CFrame:ToObjectSpace(weld.Part 1. CFrame) |
13 | weld.Parent = weld.Part 0 |
16 | connection = hitbox.Touched:Connect( function () end ) |
17 | local results = hitbox:GetTouchingParts() |
19 | coroutine.wrap( function () |
20 | for i, obj in pairs (results) do |
21 | if not results [ i ] :IsDescendantOf(char) then |
22 | local ehumanoid = results [ i ] .Parent:FindFirstChild( "Humanoid" ) |
23 | local ehumanoidRP = results [ i ] .Parent:FindFirstChild( "HumanoidRootPart" ) |
24 | if ehumanoid and ehumanoid.Health > 0 then |
28 | connection:Disconnect() |
31 | local vel = Instance.new( "BodyVelocity" ,ehumanoidRP) |
32 | vel.MaxForce = Vector 3. new( math.huge , math.huge , math.huge ) |
33 | vel.Velocity = char.HumanoidRootPart.CFrame.lookVector * 4 + Vector 3. new( 0 ,. 5 , 0 ) |
34 | game.Debris:AddItem(vel, . 5 ) |
36 | ehumanoid:TakeDamage( 2 ) |
43 | task.delay(. 08 , function () |
45 | connection:Disconnect() |