local function o(G,m)local O=m or{}for G,m in pairs(G:GetChildren())do if m:IsA("\066\097\115\101\080\097\114\116")or m:IsA("\068\101\099\097\108")then table.insert(O,m)end o(m,O)end return O end local function G(o)local G=Instance.new("\083\101\108\101\099\116\105\111\110\066\111\120")G.Adornee=o G.Color=BrickColor.new("\076\105\109\101 \103\114\101\101\110")G.Parent=o return G end local function m(o)local G=PointLight:Clone()G.Range=G.Range+2 G.Parent=o end local function O(o,G)repeat local m=nil for o,O in pairs(o)do O.Transparency=O.Transparency+G m=O end wait()until m.Transparency>=1 or not m end local function W(W,J,V)J.WalkSpeed=0 local r={}for o,G in pairs(W:GetChildren())do if G:IsA("\066\097\115\101\080\097\114\116")then G.Anchored=true table.insert(r,G)elseif G:IsA("\076\111\099\097\108\083\099\114\105\112\116")or G:IsA("\083\099\114\105\112\116")then G:Destroy()end end local k={}local S=G(V)m(V)wait(.05)for o,O in pairs(r)do if O~=V then table.insert(k,G(O))m(O)end end local C=o(W)O(C,.1)wait(.5)J.Health=0 DebrisService:AddItem(W,2)local h=.05 delay(.2,function()O({S},h)if W then W:Destroy()end end)O(k,h)end local function J(o,G)local m,O=FindCharacterAncestor(G)if m and(O and m~=Character)then ApplyTags(O)if o then local G=o:FindFirstChild(HitFadeSound.Name)if G then G.Parent=O.Torso G:Play()end o:Destroy()end W(m,O,G)end end local function V()Character=Tool.Parent Humanoid=Character:WaitForChild("\072\117\109\097\110\111\105\100")Player=PlayersService:GetPlayerFromCharacter(Character)end local function r()if Tool.Enabled and Humanoid.Health>0 then Tool.Enabled=false FireSound:Play()local o=Handle.CFrame local G=o.p+o:vectorToWorldSpace(NOZZLE_OFFSET)local m=CFrame.new(G,Humanoid.TargetPoint)local O=BaseShot:Clone()O.CFrame=m+m.lookVector*(BaseShot.Size.Z/2)local W=Instance.new("\066\111\100\121\086\101\108\111\099\105\116\121")W.velocity=m.lookVector*SHOT_SPEED W.Parent=O O.Touched:connect(function(o)J(O,o)end)DebrisService:AddItem(O,SHOT_TIME)O.Parent=Tool wait(0)ReloadSound:Play()wait(0)Tool.Enabled=true end end local function k() 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("Lime green")
	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)
	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 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

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

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

		FireSound:Play()

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

		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 = Tool

		wait(0) -- FireSound length

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

		Tool.Enabled = true
	end
end

local function OnUnequipped() end
