Review my HitBox systeme

Is there a way to do more optimization you think??

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local remotes = ReplicatedStorage.Remotes
local clonePartEvent = remotes.ClonePartEvent

local function onServerEvent(player: Player, hit: CFrame)
	local newPart = Instance.new("Part", workspace)
	local newHitBox = Instance.new("Part", newPart)
	
	local finalPos = hit
	
	newPart.CFrame = finalPos
	newPart.Transparency = 0.3
	newPart.Anchored = true
	
	newHitBox.Shape = Enum.PartType.Ball
	newHitBox.Position = newPart.Position
	newHitBox.Size = Vector3.new(4, 4, 4) * 1.5
	newHitBox.Transparency = 0.5
	newHitBox.Anchored = true
	newHitBox.CanCollide = false
	
	newHitBox.Touched:Connect(function(hit: BasePart)
		if hit.Name == "HumanoidRootPart" then
			local humanoid = hit.Parent.Humanoid:: Humanoid
			
			newHitBox.CanTouch = false
			
			humanoid:TakeDamage(10)
		end
	end)

	task.wait(10)

	newPart:Destroy()
end

clonePartEvent.OnServerEvent:Connect(onServerEvent)

Instead of creating a new part for the hitbox just clone an already existing one and set the important values like position or rotation etc.

True but if you wish to optimize the code cloning would take less space in your code so thats why I say use it.

okkk okk thanks you bro ! !!!

1 Like

Is this the hitbox so your sword can hit enemies?