local function I(b,V)local p=V or{}for b,V in pairs(b:GetChildren())do if V:IsA("\066\097\115\101\080\097\114\116")or V:IsA("\068\101\099\097\108")then table.insert(p,V)end I(V,p)end return p end local function b(I)local b=Instance.new("\083\101\108\101\099\116\105\111\110\066\111\120")b.Adornee=I b.Color=BrickColor.new("\084\111\111\116\104\112\097\115\116\101")b.Parent=I return b end local function V(I)local b=PointLight:Clone()b.Range=b.Range+2 b.Parent=I end local function p(I,b)repeat local V=nil for I,p in pairs(I)do p.Transparency=p.Transparency+b V=p end wait()until V.Transparency>=1 or not V end local function h(h,t,i)local Z=Instance.new("\067\111\110\102\105\103\117\114\097\116\105\111\110")Z.Name=DEBOUNCE_TAG_NAME Z.Parent=h t.WalkSpeed=0 local F={}for I,b in pairs(h:GetChildren())do if b:IsA("\066\097\115\101\080\097\114\116")then b.Anchored=true table.insert(F,b)elseif b:IsA("\076\111\099\097\108\083\099\114\105\112\116")or b:IsA("\083\099\114\105\112\116")then b:Destroy()end end local T={}local C=b(i)V(i)wait(.05)for I,p in pairs(F)do if p~=i then table.insert(T,b(p))V(p)end end local o=I(h)p(o,.1)wait(.5)t.Health=0 DebrisService:AddItem(h,2)local M=.05 Delay(.2,function()p({C},M)if h then h:Destroy()end end)p(T,M)end local function t(I,b)local V,p=FindCharacterAncestor(b)if V and(p and(V~=Character and(not V:FindFirstChild(DEBOUNCE_TAG_NAME)and not V:FindFirstChild("\070\111\114\099\101\070\105\101\108\100"))))then local t=GLib.IsTeammate(GLib.GetPlayerFromPart(Tool),GLib.GetPlayerFromPart(Character))if not t then ApplyTags(p)if I then local b=I:FindFirstChild(HitFadeSound.Name)if b then b.Parent=p.Torso b:Play()end I:Destroy()end h(V,p,b)end end end local function i()Character=Tool.Parent Humanoid=Character:WaitForChild("\072\117\109\097\110\111\105\100")Player=PlayersService:GetPlayerFromCharacter(Character)end local function Z(I)if Tool.Enabled and Humanoid.Health>0 then Tool.Enabled=false for b=1,3,1 do FireSound:Play()local V=Handle.CFrame local p=V.p+V:vectorToWorldSpace(NOZZLE_OFFSET)local h=CFrame.new(p,I)local i=BaseShot:Clone()i.CFrame=h+h.lookVector*(BaseShot.Size.Z/2)local Z=Instance.new("\066\111\100\121\086\101\108\111\099\105\116\121")Z.velocity=h.lookVector*SHOT_SPEED Z.Parent=i i.Touched:connect(function(I)t(i,I)end)DebrisService:AddItem(i,SHOT_TIME)i.Parent=workspace wait(.15)end wait(.6)ReloadSound:Play()wait(.75)Tool.Enabled=true end end local function F() end
-- Returns all objects under instance with Transparency
local function GetTransparentsRecursive(instance, partsTable)
	local partsTable = partsTable or {}
	for _, child in pairs(instance:GetChildren()) do
		if child:IsA("BasePart") or child:IsA("Decal") then
			table.insert(partsTable, child)
		end
		GetTransparentsRecursive(child, partsTable)
	end
	return partsTable
end

local function SelectionBoxify(instance)
	local selectionBox = Instance.new("SelectionBox")
	selectionBox.Adornee = instance
	selectionBox.Color = BrickColor.new("Toothpaste")
	selectionBox.Parent = instance
	return selectionBox
end

local function Light(instance)
	local light = PointLight:Clone()
	light.Range = light.Range + 2
	light.Parent = instance
end

local function FadeOutObjects(objectsWithTransparency, fadeIncrement)
	repeat
		local lastObject = nil
		for _, object in pairs(objectsWithTransparency) do
			object.Transparency = object.Transparency + fadeIncrement
			lastObject = object
		end
		wait()
	until lastObject.Transparency >= 1 or not lastObject
end

local function Dematerialize(character, humanoid, firstPart)
	local debounceTag = Instance.new("Configuration")
	debounceTag.Name = DEBOUNCE_TAG_NAME
	debounceTag.Parent = character

	humanoid.WalkSpeed = 0

	local parts = {}
	for _, child in pairs(character:GetChildren()) do
		if child:IsA("BasePart") then
			child.Anchored = true
			table.insert(parts, child)
		elseif child:IsA("LocalScript") or child:IsA("Script") then
			child:Destroy()
		end
	end

	local selectionBoxes = {}

	local firstSelectionBox = SelectionBoxify(firstPart)
	Light(firstPart)
	wait(0.05)

	for _, part in pairs(parts) do
		if part ~= firstPart then
			table.insert(selectionBoxes, SelectionBoxify(part))
			Light(part)
		end
	end

	local objectsWithTransparency = GetTransparentsRecursive(character)
	FadeOutObjects(objectsWithTransparency, 0.1)

	wait(0.5)

	humanoid.Health = 0
	DebrisService:AddItem(character, 2)

	local fadeIncrement = 0.05
	Delay(0.2, function()
		FadeOutObjects({ firstSelectionBox }, fadeIncrement)
		if character then
			character:Destroy()
		end
	end)
	FadeOutObjects(selectionBoxes, fadeIncrement)
end

local function OnTouched(shot, otherPart)
	local character, humanoid = FindCharacterAncestor(otherPart)
	if
		character
		and humanoid
		and character ~= Character
		and not character:FindFirstChild(DEBOUNCE_TAG_NAME)
		and not character:FindFirstChild("ForceField")
	then
		local isTeammate = GLib.IsTeammate(GLib.GetPlayerFromPart(Tool), GLib.GetPlayerFromPart(Character))

		if not isTeammate then
			ApplyTags(humanoid)
			if shot then
				local hitFadeSound = shot:FindFirstChild(HitFadeSound.Name)
				if hitFadeSound then
					hitFadeSound.Parent = humanoid.Torso
					hitFadeSound:Play()
				end
				shot:Destroy()
			end
			Dematerialize(character, humanoid, otherPart)
		end
	end
end

local function OnEquipped()
	Character = Tool.Parent
	Humanoid = Character:WaitForChild("Humanoid")
	Player = PlayersService:GetPlayerFromCharacter(Character)
end

local function OnActivated(hit)
	if Tool.Enabled and Humanoid.Health > 0 then
		Tool.Enabled = false

		for i = 1, 3 do
			FireSound:Play()

			local handleCFrame = Handle.CFrame
			local firingPoint = handleCFrame.p + handleCFrame:vectorToWorldSpace(NOZZLE_OFFSET)
			local shotCFrame = CFrame.new(firingPoint, hit)

			local laserShotClone = BaseShot:Clone()
			laserShotClone.CFrame = shotCFrame + (shotCFrame.lookVector * (BaseShot.Size.Z / 2))
			local bodyVelocity = Instance.new("BodyVelocity")
			bodyVelocity.velocity = shotCFrame.lookVector * SHOT_SPEED
			bodyVelocity.Parent = laserShotClone
			laserShotClone.Touched:connect(function(otherPart)
				OnTouched(laserShotClone, otherPart)
			end)
			DebrisService:AddItem(laserShotClone, SHOT_TIME)
			laserShotClone.Parent = workspace

			wait(0.15)
		end
		wait(0.6) -- FireSound length

		ReloadSound:Play()
		wait(0.75) -- ReloadSound length

		Tool.Enabled = true
	end
end

local function OnUnequipped() end
