local function P()local P=RocketTemplate:Clone()P.PrimaryPart.CFrame=CFrame.new(Configurations.StoragePosition.Value)P.Parent=Storage P.PrimaryPart:SetNetworkOwner(Owner)if Owner then P.PrimaryPart.BrickColor=Owner.TeamColor end table.insert(Buffer,P)end local function N()for N=1,Configurations.BufferSize.Value,1 do P()end end local function X()for P,N in ipairs(Buffer)do N.PrimaryPart:SetNetworkOwner(Owner)if Owner then N.PrimaryPart.BrickColor=Owner.TeamColor end end end local function d(P,N)local X=Players:GetPlayerFromCharacter(P.Parent)or Players:GetPlayerFromCharacter(P.Parent.Parent)if not X then if P.Parent.Name~="\082\111\099\107\101\116\076\097\117\110\099\104\101\114"and(P.Parent.Name~="\070\108\097\103"and not P.Anchored)then local X=(P.Size.X*P.Size.Y)*P.Size.Z if X<=Configurations.MaxDestroyVolume.Value then if N<Configurations.BlastRadius.Value*Configurations.DestroyJointRadiusPercent.Value then P:BreakJoints()end if#P:GetChildren()==0 then wait(2*X)P:Destroy()end end end end end local function C(P,N,X)local C=Instance.new("\069\120\112\108\111\115\105\111\110",game.Workspace)C.ExplosionType=Enum.ExplosionType.NoCraters C.DestroyJointRadiusPercent=0 C.BlastRadius=Configurations.BlastRadius.Value C.BlastPressure=Configurations.BlastPressure.Value C.Position=X C.Hit:connect(function(P,X)d(P,X,N)end)N.Part.Fire.Enabled=false wait(1)N:Destroy()end local function r(P)if P=="\080\097\114\101\110\116"then if Tool.Parent.Name=="\066\097\099\107\112\097\099\107"then local P=Tool.Parent Owner=P.Parent elseif Players:GetPlayerFromCharacter(Tool.Parent)then Owner=Players:GetPlayerFromCharacter(Tool.Parent)else Owner=nil end X()end end local function a(N,X)X.Rocket.Transparency=0 X.Part.Fire.Enabled=true P()end local function D(P,N,X)local d=Players:GetPlayerByUserId(tonumber(P))if d.TeamColor==N.TeamColor and Configurations.FriendlyFire.Value or d.TeamColor~=N.TeamColor then local P=d.Character:FindFirstChild("\072\117\109\097\110\111\105\100")if P then P:TakeDamage(X)end end end local function p(P,N)for N,X in pairs(N)do D(N,P,Configurations.SplashDamage.Value)end end local function F(P,N)D(N,P,Configurations.Damage.Value)end
-- Local Functions
local function CreateRocket()
	local rocketCopy = RocketTemplate:Clone()
	rocketCopy.PrimaryPart.CFrame = CFrame.new(Configurations.StoragePosition.Value)
	rocketCopy.Parent = Storage
	rocketCopy.PrimaryPart:SetNetworkOwner(Owner)
	if Owner then
		rocketCopy.PrimaryPart.BrickColor = Owner.TeamColor
	end

	table.insert(Buffer, rocketCopy)
end

local function IntializeBuffer()
	for i = 1, Configurations.BufferSize.Value do
		CreateRocket()
	end
end

local function ResetRocketOwner()
	for _, rocket in ipairs(Buffer) do
		rocket.PrimaryPart:SetNetworkOwner(Owner)
		if Owner then
			rocket.PrimaryPart.BrickColor = Owner.TeamColor
		end
	end
end

local function OnExplosionHit(part, distance)
	local player = Players:GetPlayerFromCharacter(part.Parent) or Players:GetPlayerFromCharacter(part.Parent.Parent)
	if not player then
		if part.Parent.Name ~= "RocketLauncher" and part.Parent.Name ~= "Flag" and not part.Anchored then
			local volume = part.Size.X * part.Size.Y * part.Size.Z
			if volume <= Configurations.MaxDestroyVolume.Value then
				if distance < Configurations.BlastRadius.Value * Configurations.DestroyJointRadiusPercent.Value then
					part:BreakJoints()
				end
				if #part:GetChildren() == 0 then
					wait(2 * volume)
					part:Destroy()
				end
			end
		end
	end
end

local function OnRocketHit(player, rocket, position)
	local explosion = Instance.new("Explosion", game.Workspace)
	explosion.ExplosionType = Enum.ExplosionType.NoCraters
	explosion.DestroyJointRadiusPercent = 0
	explosion.BlastRadius = Configurations.BlastRadius.Value
	explosion.BlastPressure = Configurations.BlastPressure.Value
	explosion.Position = position
	explosion.Hit:connect(function(part, distance)
		OnExplosionHit(part, distance, rocket)
	end)
	rocket.Part.Fire.Enabled = false
	wait(1)
	rocket:Destroy()
end

local function OnChanged(property)
	if property == "Parent" then
		if Tool.Parent.Name == "Backpack" then
			local backpack = Tool.Parent
			Owner = backpack.Parent
		elseif Players:GetPlayerFromCharacter(Tool.Parent) then
			Owner = Players:GetPlayerFromCharacter(Tool.Parent)
		else
			Owner = nil
		end
		ResetRocketOwner()
	end
end

local function OnFireRocket(player, rocket)
	rocket.Rocket.Transparency = 0
	rocket.Part.Fire.Enabled = true
	CreateRocket()
end

local function DamagePlayer(hitPlayerId, player, damage)
	local hitPlayer = Players:GetPlayerByUserId(tonumber(hitPlayerId))
	if
		(hitPlayer.TeamColor == player.TeamColor and Configurations.FriendlyFire.Value)
		or hitPlayer.TeamColor ~= player.TeamColor
	then
		local humanoid = hitPlayer.Character:FindFirstChild("Humanoid")
		if humanoid then
			humanoid:TakeDamage(damage)
		end
	end
end

local function OnHitPlayers(player, hitPlayers)
	for hitPlayerId, _ in pairs(hitPlayers) do
		DamagePlayer(hitPlayerId, player, Configurations.SplashDamage.Value)
	end
end

local function OnDirectHitPlayer(player, hitPlayerId)
	DamagePlayer(hitPlayerId, player, Configurations.Damage.Value)
end
