LocalScript:
local ArtilleryTool = script.Parent
local equippedConnection = nil
ArtilleryTool.Equipped:Connect(function()
local camera = game.Workspace.CurrentCamera
local uis = game:GetService("UserInputService")
local localPlayer = game.Players.LocalPlayer
local terrain = game.Workspace.Terrain
local function MouseRaycast()
local mousePos = uis:GetMouseLocation()
local mouseRay = camera:ViewportPointToRay(mousePos.X, mousePos.Y)
local params = RaycastParams.new()
params.FilterDescendantsInstances = {localPlayer.Character}
params.FilterType = Enum.RaycastFilterType.Exclude
return game.Workspace:Raycast(mouseRay.Origin, mouseRay.Direction * 300, params)
end
equippedConnection = uis.InputBegan:Connect(function(inp, proc)
if proc then return end
if inp.UserInputType == Enum.UserInputType.MouseButton1 then
local raycast = MouseRaycast()
if raycast then
local Navigation = Instance.new("Part")
Navigation.Parent = game.Workspace
Navigation.Position = raycast.Position
Navigation.Size = Vector3.new(5, 5, 5)
Navigation.Transparency = 1
Navigation.Material = Enum.Material.SmoothPlastic
Navigation.CanTouch = false
Navigation.CanCollide = false
Navigation.Anchored = true
Navigation.CastShadow = false
local ArtilleryBillboardGui = Instance.new("BillboardGui")
ArtilleryBillboardGui.Parent = Navigation
ArtilleryBillboardGui.AlwaysOnTop = true
ArtilleryBillboardGui.Size = UDim2.new(200, 0, 50, 0)
local ArtilleryText = Instance.new("TextLabel")
ArtilleryText.Parent = ArtilleryBillboardGui
ArtilleryText.Text = "ARTILLERY"
ArtilleryText.TextScaled = true
ArtilleryText.TextColor3 = Color3.new(255, 255, 255)
ArtilleryText.BackgroundTransparency = 1
local ArtilleryParticle = Instance.new("ParticleEmitter")
ArtilleryParticle.Parent = Navigation
ArtilleryParticle.Size = NumberSequence.new(1)
ArtilleryParticle.Transparency = NumberSequence.new(0.5)
ArtilleryParticle.Lifetime = NumberRange.new(3)
for i = 1, 12 do
wait(1.5)
local ArtilleryStartPart = Instance.new("Part")
ArtilleryStartPart.Parent = game.Workspace
ArtilleryStartPart.CastShadow = false
ArtilleryStartPart.CanCollide = false
ArtilleryStartPart.CanTouch = false
ArtilleryStartPart.Anchored = true
ArtilleryStartPart.Material = Enum.Material.SmoothPlastic
ArtilleryStartPart.Transparency = 1
ArtilleryStartPart.Size = Vector3.new(280, 80, 280)
ArtilleryStartPart.Position = Navigation.Position + Vector3.new(-300, 300, 0)
local Artillery = Instance.new("Part")
Artillery.Parent = game.Workspace
Artillery.Color = Color3.new(1, 1, 0)
Artillery.Material = Enum.Material.Neon
Artillery.Size = Vector3.new(1, 5, 1)
Artillery.Position = ArtilleryStartPart.Position
Artillery.Orientation = Vector3.new(0, 0, 45)
Artillery.CanCollide = true
local IncomingSound = script.Parent.Handle.ArtilleryIncoming
IncomingSound.RollOffMaxDistance = 500
IncomingSound.RollOffMinDistance = 100
local TweenService = game:GetService("TweenService")
local navPosition = Navigation.Position
local randomOffsetX = math.random(-80, 200)
local randomOffsetZ = math.random(-80, 80)
local goal = {}
goal.Position = Vector3.new(navPosition.X + randomOffsetX, 0, navPosition.Z + randomOffsetZ)
local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 1)
local tween = TweenService:Create(Artillery, tweenInfo, goal)
tween:Play()
IncomingSound:Play()
Artillery.Touched:Connect(function(hit)
local hitList = terrain:FillBall(Artillery.Position, 8, Enum.Material.Air, Enum.Material.SmoothPlastic)
local Sound = script.Parent.Handle.Sound
Sound.RollOffMaxDistance = 500
Sound.RollOffMinDistance = 100
local Particle = Instance.new("Explosion")
Particle.Parent = game.Workspace
Particle.Position = Artillery.Position
Particle.BlastRadius = 15
Particle.DestroyJointRadiusPercent = 0
Particle.ExplosionType = Enum.ExplosionType.NoCraters
Sound:Play()
Artillery:Destroy()
end)
end
end
end
end)
end)
ArtilleryTool.Unequipped:Connect(function()
if equippedConnection then
equippedConnection:Disconnect()
end
end)