local function R()local R=RocketTemplate:Clone()R.PrimaryPart.CFrame=CFrame.new(Configurations.StoragePosition.Value)R.Parent=Storage R.PrimaryPart:SetNetworkOwner(Owner)if Owner then R.PrimaryPart.BrickColor=Owner.TeamColor end table.insert(Buffer,R)end local function x()for x=1,Configurations.BufferSize.Value,1 do R()end end local function K(R)for x=1,#Buffer,1 do if Buffer[x]==R then table.remove(Buffer,x)return end end end local function I()for R,x in ipairs(Buffer)do x.PrimaryPart:SetNetworkOwner(Owner)if Owner then x.PrimaryPart.BrickColor=Owner.TeamColor end end end local function t(R,x)local I=Players:GetPlayerFromCharacter(R.Parent)or Players:GetPlayerFromCharacter(R.Parent.Parent)if not I then if R.Parent.Name~="\082\111\099\107\101\116\076\097\117\110\099\104\101\114"and(R.Parent.Name~="\070\108\097\103"and not R.Anchored)then local I=(R.Size.X*R.Size.Y)*R.Size.Z if I<=Configurations.MaxDestroyVolume.Value then if x<Configurations.BlastRadius.Value*Configurations.DestroyJointRadiusPercent.Value then R:BreakJoints()end if R.Parent.Name=="\082\111\099\107\101\116"then K(R.Parent)end if#R:GetChildren()==0 then wait(2*I)R:Destroy()end end end end end local function U(R,x,K)local I=Instance.new("\069\120\112\108\111\115\105\111\110",game.Workspace)I.ExplosionType=Enum.ExplosionType.NoCraters I.DestroyJointRadiusPercent=0 I.BlastRadius=Configurations.BlastRadius.Value I.BlastPressure=Configurations.BlastPressure.Value I.Position=K I.Hit:connect(function(R,K)t(R,K,x)end)x.Part.Fire.Enabled=false wait(1)x:Destroy()end local function d(R)if R=="\080\097\114\101\110\116"then if Tool.Parent.Name=="\066\097\099\107\112\097\099\107"then local R=Tool.Parent Owner=R.Parent elseif Players:GetPlayerFromCharacter(Tool.Parent)then Owner=Players:GetPlayerFromCharacter(Tool.Parent)else Owner=nil end I()end end local function A(x,K)K.Rocket.Transparency=0 K.Part.Fire.Enabled=true R()end local function h(R,x,K)local I=Players:GetPlayerByUserId(tonumber(R))if I.TeamColor==x.TeamColor and Configurations.FriendlyFire.Value or I.TeamColor~=x.TeamColor then local R=I.Character:FindFirstChild("\072\117\109\097\110\111\105\100")if R then R:TakeDamage(K)end end end local function F(R,x)for x,K in pairs(x)do h(x,R,Configurations.SplashDamage.Value)end end local function u(R,x)h(x,R,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 RemoveFromBuffer(rocket)
	for i = 1, #Buffer do
		if Buffer[i] == rocket then
			table.remove(Buffer, i)
			return
		end
	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.Parent.Name == "Rocket" then
					RemoveFromBuffer(part.Parent)
				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
