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

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
