--weld

module.weld = function(data)
	local part = data.part
	local base = data.basepart
	local tim = data.tim or nil
	local name = data.name or "Weld"
	part.Anchored = false
	--base.Anchored = false

	local Weld = Instance.new("Weld")
	Weld.Name = name
	Weld.Part0 = base
	Weld.C0 = base.CFrame:inverse()
	Weld.Part1 = part
	Weld.C1 = part.CFrame:inverse()
	Weld.Parent = Weld.Part1

	if tim then
		game.Debris:AddItem(Weld, tim)
	end
	
end

module.HitDetection = function(Data)
	local part = Data.part
	local model = part.Parent 
	local size = Data.size or Vector3.new(5,5,5)
	local Shape = Data.Shape or "Square"
	local cf = Data.cf or part.CFrame 
	local tim = Data.tim or .5
	local weld = Data.weld
	
	local tab = {}
	local db = false
	local Victum 
	local Vhum, Vroot
	
	local SpawnedHitBox = module.SpawnHB({part = part, cf =cf, size = size, tim = tim, Shape = Shape})
	tab.SpawnedHitBox = SpawnedHitBox or nil
	
	if weld then module.weld({part = SpawnedHitBox, basepart = part}) end
	
	-- HB
	local zone = Zone.new(SpawnedHitBox)
	zone:setAccuracy("High")
	zone:setDetection("WholeBody")
	--print(zone)

	task.delay(tim, function()
		db = false
		zone:destroy()
	end)

	for i, v in pairs(zone:getParts()) do
		if v and v:IsA("BasePart") then
			if v and v.Parent and v.Parent ~= model then
				if v and v.Parent and v.Parent:IsA('Model') and  v.Parent:FindFirstChild("Humanoid") and v.Parent:FindFirstChild("HumanoidRootPart") and v.Parent:FindFirstChild("Humanoid").Health > 0 then
					if db == false then
						db = true
						
						Victum =  v.Parent
						
						zone:destroy()
						SpawnedHitBox:Destroy()
					end
				end
			end
		end
	end	

	-- 
	
	if Victum then Vhum, Vroot =Victum:FindFirstChild("Humanoid"), Victum:FindFirstChild("HumanoidRootPart") end
	tab.Victum = Victum or nil
	tab.Vhum = Vhum or nil
	tab.Vroot = Vroot or nil
	
	return tab
end

return module
