local function N()local N=Instance.new("\080\097\114\116")N.Name="\082\111\099\107\101\116"N.FormFactor=Enum.FormFactor.Custom N.Size=ROCKET_PART_SIZE N.CanCollide=false N.BottomSurface=Enum.SurfaceType.Smooth N.TopSurface=Enum.SurfaceType.Smooth local C=Instance.new("\083\112\101\099\105\097\108\077\101\115\104",N)C.MeshId=ROCKET_MESH_ID C.Scale=ROCKET_MESH_SCALE C.TextureId=ToolHandle.Mesh.TextureId local D=Instance.new("\070\105\114\101",N)D.Heat=5 D.Size=2 local Z=Instance.new("\082\111\099\107\101\116\080\114\111\112\117\108\115\105\111\110",N)Z.CartoonFactor=1 Z.TargetRadius=TARGET_RADIUS Z.MaxSpeed=MAX_SPEED Z.MaxTorque=MAX_TORQUE Z.MaxThrust=MAX_THRUST Z.ThrustP=THRUST_P Z.ThrustD=THRUST_D local j=SwooshSound:Clone()j.Parent=N local l=BoomSound:Clone()l.Parent=N local O=Instance.new("\079\098\106\101\099\116\086\097\108\117\101",N)O.Name="\099\114\101\097\116\111\114"O.Value=MyPlayer local a=Instance.new("\083\116\114\105\110\103\086\097\108\117\101",O)a.Name="\105\099\111\110"a.Value=Tool.TextureId local S=RocketScript:Clone()S.Parent=N S.Disabled=false return N end local function C()MyModel=Tool.Parent MyPlayer=PlayersService:GetPlayerFromCharacter(MyModel)BaseRocket=N()RocketClone=BaseRocket:Clone()end local function D(N)if Tool.Enabled and(MyModel and(MyModel:FindFirstChild("\072\117\109\097\110\111\105\100")and MyModel.Humanoid.Health>0))then Tool.Enabled=false local C=MyModel.Humanoid.TargetPoint if N then C=MyModel.Humanoid.Torso.CFrame.lookVector*1000 end local D=ToolHandle.Position+ToolHandle.CFrame.lookVector*(ToolHandle.Size.z/2)RocketClone.CFrame=CFrame.new(D,C)DebrisService:AddItem(RocketClone,30)RocketClone.Parent=Workspace local Z=RocketClone:FindFirstChild("\082\111\099\107\101\116\080\114\111\112\117\108\115\105\111\110")if Z then local N=(C-RocketClone.Position).unit Z.TargetOffset=RocketClone.Position+N*TARGET_OVERSHOOT_DISTANCE Z:Fire()end wait(0)local j=RocketClone:FindFirstChild("\083\119\111\111\115\104")if j then j:Play()end RocketClone=BaseRocket:Clone()ReloadSound:Play()wait(COOLDOWN)ReloadSound:Stop()Tool.Enabled=true end end local function Z()ReloadSound:Stop()end
-----------------
--| Functions |--
-----------------

local function MakeBaseRocket()
	-- Set up the rocket part
	local rocket = Instance.new("Part")
	rocket.Name = "Rocket"
	rocket.FormFactor = Enum.FormFactor.Custom --NOTE: This must be done before changing Size
	rocket.Size = ROCKET_PART_SIZE
	rocket.CanCollide = false
	rocket.BottomSurface = Enum.SurfaceType.Smooth
	rocket.TopSurface = Enum.SurfaceType.Smooth

	-- Add the mesh
	local mesh = Instance.new("SpecialMesh", rocket)
	mesh.MeshId = ROCKET_MESH_ID
	mesh.Scale = ROCKET_MESH_SCALE
	mesh.TextureId = ToolHandle.Mesh.TextureId

	-- Add fire
	local fire = Instance.new("Fire", rocket)
	fire.Heat = 5
	fire.Size = 2

	-- Add the propulsion
	local rocketPropulsion = Instance.new("RocketPropulsion", rocket)
	rocketPropulsion.CartoonFactor = 1
	rocketPropulsion.TargetRadius = TARGET_RADIUS
	rocketPropulsion.MaxSpeed = MAX_SPEED
	rocketPropulsion.MaxTorque = MAX_TORQUE
	rocketPropulsion.MaxThrust = MAX_THRUST
	rocketPropulsion.ThrustP = THRUST_P
	rocketPropulsion.ThrustD = THRUST_D

	-- Clone the sounds
	local swooshSoundClone = SwooshSound:Clone()
	swooshSoundClone.Parent = rocket
	local boomSoundClone = BoomSound:Clone()
	boomSoundClone.Parent = rocket

	-- Attach creator tags
	local creatorTag = Instance.new("ObjectValue", rocket)
	creatorTag.Name = "creator" --NOTE: Must be called 'creator' for website stats
	creatorTag.Value = MyPlayer
	local iconTag = Instance.new("StringValue", creatorTag)
	iconTag.Name = "icon"
	iconTag.Value = Tool.TextureId

	-- Finally, clone the rocket script and enable it
	local rocketScriptClone = RocketScript:Clone()
	rocketScriptClone.Parent = rocket
	rocketScriptClone.Disabled = false

	return rocket
end

local function OnEquipped()
	MyModel = Tool.Parent
	MyPlayer = PlayersService:GetPlayerFromCharacter(MyModel)
	BaseRocket = MakeBaseRocket()
	RocketClone = BaseRocket:Clone()
end

local function OnActivated(byFireButton)
	if Tool.Enabled and MyModel and MyModel:FindFirstChild("Humanoid") and MyModel.Humanoid.Health > 0 then
		Tool.Enabled = false

		-- Get the target position
		local targetPosition = MyModel.Humanoid.TargetPoint
		if byFireButton then -- Using Fire Button, shoot forwards
			targetPosition = MyModel.Humanoid.Torso.CFrame.lookVector * 1000
		end

		-- Position the rocket clone
		local spawnPosition = ToolHandle.Position + (ToolHandle.CFrame.lookVector * (ToolHandle.Size.z / 2))
		RocketClone.CFrame = CFrame.new(spawnPosition, targetPosition) --NOTE: This must be done before assigning Parent
		DebrisService:AddItem(RocketClone, 30)
		RocketClone.Parent = Workspace

		-- Assign target and launch!
		local rocketPropulsion = RocketClone:FindFirstChild("RocketPropulsion")
		if rocketPropulsion then
			local direction = (targetPosition - RocketClone.Position).unit
			rocketPropulsion.TargetOffset = RocketClone.Position + (direction * TARGET_OVERSHOOT_DISTANCE)
			rocketPropulsion:Fire()
		end

		wait(0) --TODO: Remove when sounds realize they can be played as soon as they enter the Workspace

		-- Swoosh!
		local swooshSound = RocketClone:FindFirstChild("Swoosh")
		if swooshSound then
			swooshSound:Play()
		end

		-- Prepare the next rocket to be fired
		RocketClone = BaseRocket:Clone()

		ReloadSound:Play()

		wait(COOLDOWN)

		-- Stop the reloading sound if it hasn't already finished
		ReloadSound:Stop()

		Tool.Enabled = true
	end
end

local function OnUnequipped()
	ReloadSound:Stop() --TODO: This does not work online
end
