How to make all players see Artillery?

image

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)
4 Likes

if only you’d provide more information about what exactly you are trying to do…

2 Likes

I’m gonna assume their artillery tool is client sided since it only has a local script and the code he provided is for a local script.

So all he really needs to do make a remote event, send position data to the event and handle the rest on the server

2 Likes

you’re saying that his artillery is invisible on the server side and is only visible on the cleint when equipped?

2 Likes

Seems like it. The title being what it is and everything being in a local script I’m guessing it’s all client side hence why other people can’t see it. Also no remotes are being used in the local script so that would kind of confirm it.

2 Likes

Yes, that’s right, it’s a local script and it’s not visible to the server. I need to use Remote Event?

Yup. You need to use Remote Events for Client to Server communication (or vice versa).
In this case you can put a RemoteEvent in ReplicatedStorage or your tool, then fire the event to the server using RemoteEvent:FireServer() whenever you fire the artillery.

2 Likes